#Why does the Allocator interface require the size of the memory block to free it?
1 messages · Page 1 of 1 (latest)
it helps to simplify allocator implementations. For implementations that have to accept just a pointer, you have to spend memory on metadata
at worst, you waste maybe 8 bytes on the call, because the allocator already tracks the allocation length (e.g., using an allocator designed in C) - and even then, this still allows you to add a safety check like "memory free length mismatch"
on the other hand, you do need to implement 'shrink', which surely makes some simple linear allocs harder
You're allowed to make resize always fail if you want! Until recently, it was true that shrinks were expected to always succeed, but that was changed for precisely this reason - it potentially required allocators to store state they otherwise wouldn't need