Finalizing D2

Lionello Lunesu lio at
Mon May 25 04:17:34 PDT 2009

Andrei Alexandrescu wrote:
> grauzone wrote:
>>>>> * std.mmfile: integrate with the garbage collector. It should be 
>>>>> there.
>>>> Why should the GC know about it?
>> To add: in all sane situations, the mmaped region won't contain any 
>> pointers, and the GC doesn't have to scan it. Allocating address space 
>> is already done by the OS. Freeing the mmaped region is not the GC's 
>> responsibility, but can be left to finalizers/destructors.
>>> Because the only way to make memory-mapped files safe is to have the 
>>> GC handle them.
>> Care to explain?
> mmhandle h = mapFile("test.txt");
> char[] x = cast(char[]) h.ptr;
> h.unmapFile;
> Any attempt to use x will crash the program. So it's the gc who needs to 
> unmap files when they are no longer referenced.

Memory mapped files are unlike memory in that they keep the actual 
mapped file locked. There must be a deterministic way to unlock those 


More information about the Digitalmars-d mailing list