The definition of malloc_usable_size()

H. Peter Anvin hpa@zytor.com
Mon May 4 18:11:57 GMT 2026


On 2026-05-04 11:03, DJ Delorie wrote:
> "H. Peter Anvin" <hpa@zytor.com> writes:
>> (meaning returned a value larger than what would actually be safe to
>> use?)
> 
> That's not what the definition says.  It only says that it's
> *unsupported*, which means, if you write code that does it, you don't
> get to complain if it stops working.
> 

Certainly, but you know just as well as I do that breaking random applications
isn't a reasonable thing to do.

So what I'm saying is that maybe if that is the *de facto* API we should just
bite the bullet and make it the *de jure* API.

In order words, have malloc_usable_size() return the largest value the the
memory manager guarantees will remain allocated to the application, which will
be >= the requested size.

Since an allocator which may shrink the allocation size needs to know what the
promised allocation size is, it *must* be available, and thus a future
implementation with that property can return *that* value.

	-hpa



More information about the Libc-alpha mailing list