I don't agree. Zig allocators require the size of the allocation (technically they take a slice, but a slice is ptr + size), as does the C++ polymorphic allocator, as does many allocator interfaces in many libraries (see for instance the allocator interface in Lua, my personal favorite C interface for memory allocation [0]). Clearly having it as a correctness requirement works just fine.
Re:The lost malloc()
by 0xdeafbeef on Wednesday November 04, 2026 @07:43AM
(#50364784)
https://github.com/microsoft/mimalloc/issues/1423
https://github.com/microsoft/mimalloc/issues/1400
And there also bugs for zig. So hint - fine. Trust it? Not sure. Every allocator is different and can be swapped
> "void*" sadly exists
But _somewhere_ you need to know what it represents, otherwise it's useless.
> I tried using TCMalloc with rustc, and it segfaulted. Rust knows the sizes of its allocations, but things can still go wrong at the allocator boundary.
Things can go wrong, doesn't mean they will go wrong due to the reasons you're thinking of.
I tried using TCMalloc with rustc, and it segfaulted. Rust knows the sizes of its allocations, but things can still go wrong at the allocator boundary.
Size should be an optimization hint, not a correctness requirement. Otherwise, it's just another security pitfall