Hacker News
points by 0xdeafbeef 4 days ago | 0 comments
"void*" sadly exists, and there are a lot of edge cases.

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

[–] OskarS 4 days ago
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.

[0]: https://www.lua.org/manual/5.4/manual.html#lua_Alloc

[–] 0xdeafbeef 4 days ago
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

[–] SkiFire13 4 days ago
> "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.