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.
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.
Re:The lost malloc()
by 1718627440 on Wednesday November 04, 2026 @04:52PM
(#50372068)
At load time, you do know whether a program is going to use plain free, so you can select the implementation then.
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.