www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - delete and MmFile

reply NewName <b5353166 nwldx.com> writes:
Hello everybody.
So I heard that `delete' is being deprecated?

If that's true, what can I do to close an MmFile?
Or is there another way to create an MmFile object, other than with `new', so
that it gets destroyed when out of scope?

My problem is, I need to reopen the same file outside an if() block. If the
conditional is entered and I don't delete the MmFile in it, my program will
crash at runtime.
Presumably for trying to map the same file twice.

Thank you.
Jan 28 2012
parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"NewName" <b5353166 nwldx.com> wrote in message 
news:jg2du7$2nun$1 digitalmars.com...
 Hello everybody.
 So I heard that `delete' is being deprecated?
When delete is gone, you will still be able to destroy class instances with 'clear' from phobos. Like delete, it runs the destructor on the class, it just doesn't actually free the memory, it leaves it for the gc. When the destructor is called the resources held by MmFile should be released.
Jan 28 2012
parent reply NewName <b5353166 newldx.com> writes:
Thanks Daniel.
So clear() is a function thing, so my delete mmf; will look like clear(mmf); am
I
right?
Jan 28 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
Yes.  clear is in object.d so it will always be available.

"NewName" <b5353166 newldx.com> wrote in message 
news:jg2fdj$2rmk$1 digitalmars.com...
 Thanks Daniel.
 So clear() is a function thing, so my delete mmf; will look like 
 clear(mmf); am I
 right?
 
Jan 28 2012