← Back to context

Comment by 0xdeafbeef

24 days ago

"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

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

> "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.