DMD 1.001 release

Sean Kelly sean at f4.ca
Thu Jan 25 13:42:52 PST 2007


Tomas Lindquist Olsen wrote:
> Frits van Bommel wrote:
> 
>> Walter Bright wrote:
>>> Tomas Lindquist Olsen wrote:
>>>> Let me clarify what I mean. Consider this code:
>>>>
>>>> import std.gc;
>>>>
>>>> void test()
>>>> {
>>>>    void[] buf = new void[1024];
>>>>    std.gc.hasNoPointers(ret.ptr);
>>>>    // invoking gc will not scan buf. ok
>>>>    buf.length = buf.length*2;
>>>>    // could invoking gc now potentially scan buf?
>>>> }
>>>>
>>>> I'm thinking how to make sure a void[] is never scanned.
>>>> A somewhat realistic case for this would be (again) the
>>>> std.file.read function.
>>>> If we append some data to this buffer will the GC be smart enough
>>>> to know it still holds no pointers? That is even with the
>>>> reallocation and potential relocation.
>>> It'll reallocate based on the type of buf, which is void[], so
>>> you'll  need to invoke gc.hasNoPointers again.
>> Shouldn't it copy pointer-ness from the original to the new array?
>> That seems like the logical thing to do.  The same applies to
>> concatenating arrays, though perhaps that should follow the rule "the
>> new array contains pointers if either original array contained
>> pointers".
> 
> This is what I'm thinking as well. Just dropping the information is not
> acceptable IMHO. It means that you have to call hasNoPointers every
> time you resize a void[] to be sure the GC is handling it like you
> indended.

I've been mulling this over the past few weeks, and even went so far as 
to begin a patch to do this, but I'm undecided.  First, it could work 
one of two ways: either it could be made to only affect resizing of the 
original array itself, or it could be made to affect resizing of that 
array and any slices of that array.  The latter behavior seems to make 
the most sense from a consistency perspective, but I worry that making 
such an attribute "viral" could result in unpredictable behavior in 
large applications where slices are passed into contexts which may be 
unaware of the slice's origin.  For the moment, I've decided to wait and 
see how much of an issue this turns out to be, and I'll probably finish 
the GC mods to support it efficiently just in case.


Sean



More information about the Digitalmars-d-announce mailing list