[Issue 9092] GC.extend allocates less then it reports

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 1 01:45:48 PST 2012


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



--- Comment #3 from Rainer Schuetze <r.sagitario at gmx.de> 2012-12-01 01:45:26 PST ---
> I passed a pointer (a.ptr) to extend, and extend promised that memory location
> was extended to a certain amount. if a.ptr did not actually point to the
> beginning of a memory location, then why/how was it extended? And if extend was
> able to detect that a.ptr was already 16 bytes into my memory block, then why
> can't it take that into account when replying?

You expect different stuff from GC.extend than its author: "Attempt to in-place
enlarge the memory block pointed to by p by at least minbytes beyond its
current capacity, up to a maximum of maxsize.  This does not attempt to move
the memory block (like realloc() does).
     * Returns:
     *  0 if could not extend p,
     *  total size of entire memory block if successful." (gcx.d)

At GC level, the actual usage of that memory as an array is unknown. When you
access a.ptr[size-of-memory-block - 1] you read/write outside of the memory
block which can cause page faults or not, depending on whether the following
page was mapped by the OS or not. 

You can use capacity(a) to get the number of available array slots in the
current memory block.


> Anyways, here is Appender subject to this bug...

I agree, this is a bug in the appender code that assumes the same things that
you do.

-- 
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