DMD 1.001 release
Tomas Lindquist Olsen
tomas at famolsen.dk
Thu Jan 25 08:46:15 PST 2007
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.
More information about the Digitalmars-d-announce
mailing list