Question about garbage collection specification

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 13 15:49:21 PDT 2015


On 6/13/15 6:07 PM, deadalnix wrote:
> On Saturday, 13 June 2015 at 11:32:20 UTC, rsw0x wrote:
>> http://dlang.org/garbage.html
>>
>> Do not take advantage of alignment of pointers to store bit flags in
>> the low order bits:
>> p = cast(void*)(cast(int)p | 1);  // error: undefined behavior
>>
>> if this restriction is actually imposed - why does
>> std.bitmanip.tagged{ClassRef,Pointer} even exist?
>
> That seems like an arbitrary limitation. This will create an interior
> pointer, which the GC needs to recognize anyway.
>
> The doc need to be updated.

void *x = new int;
ptr += 1;

Is this illegal? If not, then why is the above illegal? If so, thousands 
of lines of code are in violation -- any kind of serialization library 
for example.

It's exactly the same thing. We can probably change taggedPointer to do 
this instead, if it's such a big deal. We can change it to a void 
pointer, and only cast it to T* when retrieving the real pointer.

But it seems kind of silly to outlaw the obvious implementation. I think 
we should revert the warning and fix the docs.

-Steve


More information about the Digitalmars-d mailing list