Hacker News
points by wahern 3 days ago | 0 comments
C2y has already added free_sized, FWIW, which is symmetrical with malloc. See 7.25.4.7 in the latest draft at https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3998.pdf

It also adds free_aligned_sized as the counterpart to C11's aligned_alloc. Though while you can pass memory from aligned_alloc to free, you can't use free_sized or free_aligned_sized with aligned_alloc'd or malloc'd memory respectively, a potential (and unavoidable?) foot gun.

[–] dooglius 3 days ago
But if you still have to support the plain free functions it doesn't help because you'd still have to track the information anyway.
[–] wahern 3 days ago
The degree to which it helps or not depends on the implementation. For example, free could be a slow path that does extra bookkeeping lookups the sized variants wouldn't need to. Large allocations and non-default aligned allocations often use different bookkeeping data structures from how most allocations are handled internally anyhow. In such cases that check needs to be done up front, and at least on virtual memory systems (where it's relatively easy to segregate allocations types by VM range) it doesn't much matter whether you're indexing that first level directory based on pointer or size.

But, yeah, it's not an ideal situation from the perspective of free_aligned advocates.

[–] 1718627440 3 days ago
At load time, you do know whether a program is going to use plain free, so you can select the implementation then.