A question regarding the GC

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Jul 20 06:43:01 PDT 2008


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:g5v9je$uos$1 at digitalmars.com...
> torhu:
>> Are you aware of std.gc.capacity()?
>
> The docs say:
>>uint capacity(void* p); Returns capacity (size of the memory block) that p 
>>points to the beginning of. If p does not point into the gc memory pool, 
>>or does not point to the beginning of an allocated memory block, 0 is 
>>returned.<
>
> Is it safe to read/write all the bytes of such capacity (even if it's 
> higher than the size of the requested memory block)?

Yes, the GC always allocates memory blocks in sizes that are powers of two, 
at least up to the size of an OS memory page.  After that I think it's 
rounded up to some number of pages.  So yes, a lot of times there will be 
"holes" after your allocations that you can access with pointer trickery. 




More information about the Digitalmars-d-learn mailing list