GC.sizeOf(array.ptr)

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 30 07:24:27 PDT 2014


On Tuesday, 30 September 2014 at 14:01:17 UTC, Steven 
Schveighoffer wrote:
>> Assertion passes with D1/Tango runtime but fails with current 
>> D2
>> runtime. This happens because `result.ptr` is not actually a 
>> pointer
>> returned by gc_qalloc from array reallocation, but interior 
>> pointer 16
>> bytes from the start of that block. Druntime stores some 
>> metadata
>> (length/capacity I presume) in the very beginning.
>
> This is accurate, it stores the "used" size of the array. But 
> it's only the case for arrays, not general GC.malloc blocks.
>
> Alternative is to use result.capacity, which essentially looks 
> up the same thing (and should be more accurate). But it doesn't 
> cover the same inputs.

Why is it stored in the beginning and not in the end of the block 
(like capacity)? I'd like to explore options of removing interior 
pointer completely before proceeding with adding more special 
cases to GC functions.


More information about the Digitalmars-d mailing list