<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I've been thinking about how best to address the problem that the GC currently doesn't finalize structs in conjunction with tracking append metadata, precise scanning, etc. The current pertinent GC interface is roughly as follows:<div><br></div><div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(size_t, uint) gc_malloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) BlkInfo function(size_t, uint) gc_qalloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(size_t, uint) gc_calloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(void*, size_t, uint ba) gc_realloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) size_t function(void*, size_t, size_t) gc_extend;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) size_t function(size_t) gc_reserve;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void function(void*) gc_free;</font></div></div><div><br></div><div>What I'd like to do is this:</div><div><br></div><div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(TypeInfo) gc_alloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(TypeInfo, size_t) gc_allocn;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) size_t function(void*, size_t, size_t) gc_extend;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(size_t, uint) gc_malloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) size_t function(size_t) gc_reserve;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void function(void*) gc_free;</font></div></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">// reevaluate</font></div><div><font class="Apple-style-span" face="Courier">extern (C) size_t function(void*, size_t, size_t) gc_extend;</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">// deprecate</font></div><div><font class="Apple-style-span" face="Courier">extern (C) void* function(void*, size_t, uint ba) gc_realloc;</font></div><div><font class="Apple-style-span" face="Courier">extern (C) BlkInfo function(size_t, uint) gc_qalloc;</font></div><div><br></div><div>gc_alloc() and gc_allocn() would become the default GC allocator routines and would set any necessary flags based on the supplied type, store the pointer bitmap, initialize the block based on ti.init[], etc.</div><div><br></div><div>gc_malloc() will remain as-is because I suspect there will always be a need for using D as a "better C." If this becomes an array of structs the user would be responsible for supplying the TypeInfo later (or finalizer or whatever).</div><div><br></div><div>gc_qalloc() should be rendered largely useless by the addition of gc_alloc() and gc_allocn(), since the need for gc_qalloc() was mostly to efficiently do stuff in lifetime.d that would instead be handled by the GC. Steve, is this accurate?</div><div><br></div><div>gc_realloc() has never seen much use and promises to become increasingly more complicated as TypeInfo is added, etc. I'd prefer to just drop it and let the user call gc_extend() if he wants to resize memory in place. This would require allowing gc_extend() to be used on sub-page sized blocks, but this seems reasonable anyway. If I have a 150 byte array in a 256 byte block I should be allowed to extend it to 256 bytes. Doing so is basically a no-op, but it frees the user from having to query the block size to determine how to handle an array append operation, for example.</div><div><br></div><div>Finally, I really want to change the APPENDABLE bit to NO_APPEND/STATIC/SINGLE/whatever since the default (zero value) behavior should be that an allocated block is not an array.</div><div><br></div><div>Thoughts?</div></body></html>