[Issue 10589] GC.malloc(sz, GC.BlkAttr.APPENDABLE) fails after a certain size

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 12 13:38:24 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10589


Rainer Schuetze <r.sagitario at gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario at gmx.de


--- Comment #1 from Rainer Schuetze <r.sagitario at gmx.de> 2013-07-12 13:37:39 PDT ---
I think you are mixing two levels of abstractions here:

        ubyte*  p = cast(ubyte*)GC.malloc(i, GC.BlkAttr.APPENDABLE);
        ubyte[] s = p[0 .. 0];
        writefln("%6s: s.capacity  is %6s", i, s.capacity);

GC.malloc requests raw memory from the GC. capacity is a function very specific
to the way arrays are implemented on top of it in rt/lifetime.d. It assumes
that any allocation with bit APPENDABLE set and that is larger than a page of
4kB reserves 16 bytes at the start of the allocation to store the actually used
length of the memory.

So, to create an empty array manually that works with capacity, you'd have to
set s to

   auto start = i <= 2048 ? 0 : 16;
   ubyte[] s = p[start .. start];

and you'd better clean that full memory block first to avoid the length field
containing garbage.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list