Question about garbage collection specification

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 15 12:29:31 PDT 2015


On Monday, 15 June 2015 at 12:49:25 UTC, Steven Schveighoffer 
wrote:
> On 6/15/15 8:08 AM, Dmitry Olshansky wrote:
>> On 13-Jun-2015 14:32, 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?
>>
>> AFAIK the restriction was that pointers _themselves_ have to 
>> be stored
>> at word-aligned addresses. This allows GC to scan memory 
>> cheaper w/o
>> considering if some misaligned address may contain a pointer.
>
> That doesn't make sense. Why would you want to do this?
>
> The only rational thing I can think of is that you wouldn't 
> want to store the result in an *actual* int pointer (lest it be 
> used thinking it was valid without masking out the lower bits). 
> But the example is storing it in a void *...
>
> -Steve

I think you miread it.

The memory the pointer points to can be misaligned.
The memory the pointer is in must be aligned.

Note that the second is mandatory is various hardware 
architecture to begin with, so it is not like it is a big 
constraint. It allow the GC to scan faster. It is all good.

The first one do not make any sense as GC need to support 
interior pointers anyway.


More information about the Digitalmars-d mailing list