Neat project: add pointer capability to std.bitmanip.bitfields

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 3 05:02:24 PST 2015


On 12/3/15 7:20 AM, Marc Schütz wrote:
> On Wednesday, 2 December 2015 at 23:38:33 UTC, deadalnix wrote:
>> On Wednesday, 2 December 2015 at 23:04:16 UTC, ZombineDev wrote:
>>> On Wednesday, 2 December 2015 at 19:39:47 UTC, Andrei Alexandrescu
>>> wrote:
>>>> Once done, this is a fantastic example of (a) the power of
>>>> generative programming, and (b) the advantages of using library
>>>> facilities instead of built-in features.
>>>>
>>>> https://issues.dlang.org/show_bug.cgi?id=15397
>>>>
>>>> Who would want to take it?
>>>>
>>>>
>>>> Andrei
>>>
>>> So, something like
>>> http://dlang.org/phobos/std_bitmanip.html#.taggedPointer?
>>
>> Yeah, that'd be great if we could remove these scary warning about the
>> GC on these, this is only FUD. It works just fine with the GC.
>
> With the current GC, yes. If we allow this, any future GC implementation
> will have to expect pointers to be misaligned. If a GC is type aware, it
> can use this information to reject false pointers without having to look
> them up. Anyway, I guess that will not affect performance much, so it's
> probably ok.

First I will say, there is confusion on what is valid and what is not. 
Misaligned pointers are pointers that are stored misaligned. In other 
words, they are stored not on a 4-byte or 8-byte boundary for 32 bits or 
64 bits arch respectively.

An interior pointer is a pointer that is *properly aligned* but does not 
point at the first byte of a piece of memory. taggedPointer and 
taggedClassRef create *interior pointers*, not *misaligned pointers*. 
Andrei's proposal will create *misaligned pointers*. There is a huge 
difference.

I can make an interior pointer without casts on any type:

SomeType *pointer = ...;
void[] p = pointer[0..1];
p = p[1..$];

If the GC does not support this being the only pointer to a memory 
location, then the GC is not suitable for D. Period. Code will break in 
subtle ways if you use such a GC.

I can't see how a language with void* and/or unions could allow such a GC.

-Steve


More information about the Digitalmars-d mailing list