How do I create a new file using phobos ?
Daniel Keep
daniel.keep.lists at gmail.com
Fri Sep 21 18:02:32 PDT 2007
Frits van Bommel wrote:
> Bill Baxter wrote:
>> Wait a minute, can anyone confirm that it's ok to use a scope
>> BufferedFile without explicitly closing?
>> BufferedFile contiains a 'new File()', but no destructor. The File's
>> destructor contains a close(), however. So will the member File's
>> destructor get called when the scope BufferedFile goes out of scope?
>>
>> It's really just a question of how scope works w.r.t classes with heap
>> allocated members. Do the reference members get deleted
>> deterministically on scope exit too?
>
> No, they don't. You'd have to wait until they get GC'd. Yes, this sucks.
>
> Putting "scope(exit) file.close;" right after your declaration should
> make the case in the example behave properly...
You know what I'd *kill* for?
class Llama
{
string foo;
Object bar;
scope InputStream baz;
scope ubyte[] quxx;
~this()
{
// Can't do much here; could be GC'ed :'(
}
scope ~this()
{
// EVERYBODY DIES!!
delete foo;
delete bar;
// baz automatically gets scope ~this'ed & delete'd.
// quxx automatically gets delete'd.
}
}
Yeah, yeah; I'll go back to wishing wistfully...
-- Daniel
More information about the Digitalmars-d
mailing list