A question regarding the GC

Sean Kelly sean at invisibleduck.org
Sun Jul 20 13:04:42 PDT 2008


Sean Kelly wrote:
> bearophile wrote:
>> Sean Kelly:
>>> Since the GC provides a method to obtain this information I believe 
>>> that implicit permission has been given to use the capacity 
>>> indicated.  After all, the GC wouldn't tell you about capacity it 
>>> didn't want you to use :-)
>>
>> I see.
>> (So far I have meant the capacity value as the higher value the GC can 
>> realloc the memory block until it needs to copy the block to a new 
>> position. I have meant it as little useful value. Now I'll find better 
>> ways to use it, the first usage will probably be in the implementation 
>> of a templeted unrolled linked list :-) ).
>>
>> Related note: the std.c.malloc() too must store the size of the 
>> allocated block somewhere, but I presume such value can't be found in 
>> simple ways...
> 
> You'd have to know how the allocator was implemented, or modify it (in 
> the case of an open source allocator like nedmalloc) to add the routine. 
>  This is one call that I wish had been in C from the start.  Oh well.

Oh, for what it's worth... some allocators can claim adjoining free 
blocks when reallocating.  I would not expect the GC to report this 
memory as available capacity because it isn't technically part of the 
memory block in question and so may disappear at some point.  That is, I 
would say that capacity() should only return the already reserved space 
for the block in question.


Sean


More information about the Digitalmars-d-learn mailing list