[D-runtime] Precise garbage collection

Rainer Schuetze r.sagitario at gmx.de
Fri Jun 21 14:37:45 PDT 2013


On 21.06.2013 22:22, Steven Schveighoffer wrote:
>> d2. Both dynamic and associative arrays currently allocate memory chunks and use them in a "non-standard" way that cannot be described by a simple TypeInfo. For example, dynamic arrays keep track of the allocated size of the array by placing it at the very end of allocations < 4k, but at the beginning for allocations >= 4k, moving the data to an offset of 16 in the latter case. Associative arrays combine hash-list-node, key and value into a single allocation, sometimes even with the value type unavailable.
>
> The dynamic array "allocated size" location and size is predictable, and can be determined whether it exists based on the APPENDABLE bit.  You should be able to correctly ignore it during a collection.  Or am I misunderstanding the reason you posted that?


The size value itself is only a small issue, the larger one is the 
address of the array data moves depending on the size of the allocation, 
so the pointer info needs to be placed at some offset sometimes. My 
first implementation actually figured this out in the GC, but I think 
this leaks too much implementation details of the array into the GC. So 
I changed it to use gc_emplace instead.



More information about the D-runtime mailing list