back to arays

Unknown W. Brackets unknown at simplemachines.org
Wed May 17 22:07:12 PDT 2006


I should note, currently, DMD's implementation won't move anything 
you're pointing to.

And... as you probably know, memory is allocated in chunks from the 
operating system.  Without making a copy, you can't deallocate just one 
part.  So DMD won't currently.

However, if the memory were to be copied I'd expect it to be perfectly 
reasonable that the GC might not keep the old array data (although that 
would certainly be non-trivial for the GC to do.)

I wouldn't depend on it - and it seems brittle anyway, even if it were 
guaranteed.

-[Unknown]


> There's one more question about arrays.
> 
> From D specs:
> 
>> A pointer to the start of a garbage collected object need not be maintained if a pointer to the interior of the object exists.
>> char[] p = new char[10];
>> char[] q = p[3..6];
>> // q is enough to hold on to the object, don't need to keep
>> // p as well.
> 
> If the garbage collector moves data referenced by p, i guess all
> pointers to slices of p will be updated correctly.  
> 
> What if i set p to null or p goes out of scope and q is still
> reachable, will the memory (before q.ptr and after q.ptr + q.length -
> 1) that was pointed to by p be reclaimed by the garbage collector? 
> 



More information about the Digitalmars-d-learn mailing list