Memory allocation in D (noob question)

mandel oh at no.es
Mon Dec 3 13:59:06 PST 2007


Steven Schveighoffer wrote:
[..]
> Now I create the valid array slices:
> 
> int[] array3 = array1[$..$];
> int[] array4 = array2[0..0];
> 
> Note that both of these arrays are bit-for-bit identical (both have 0
> length and the same ptr value).  Which one points to which piece of
> memory?  How is the GC to decide which memory gets collected?
I see the problem.
The first possible solution that comes to my mind seeing this is to
make array1[0..0] and array1[$..$] equal.
array1[$..$] could point to the begin of the array.
Since the slice length is null, it shouldn't matter - would it?

Second thought, why not ignore empty slices at all by telling
the GC that the pointers doesn't hold any data.

Anyway, I guess there some things I missed. ;-)


[..]
> I hope this helps your understanding of the issue.
Yes, it does. :)




More information about the Digitalmars-d mailing list