Proposed addition of malloc_size_np()

Robert Watson rwatson at FreeBSD.org
Sun Mar 26 11:11:20 UTC 2006


On Sat, 25 Mar 2006, Jason Evans wrote:

>> Ok, so what you are saying is that the function returns the size of the 
>> bucket (if any) that the memory was allocated from...  But even though this 
>> function may return a larger value, the program is not allowed to use extra 
>> space, and it's only useful for further allocations of the same size?
>
> I'm saying that malloc_size_np() returns the size of the allocation, to the 
> best of the allocator's knowledge.  If you malloc(17), and malloc_size_np() 
> returns 32 for that allocation, then you can treat it as a 32-byte 
> allocation.  However, the malloc implementation could conceivably return any 
> value >=17.

I wonder if the intuitive objection people are raising is actually with the 
name.  Since malloc_size() is defined on at least one platform to return the 
requested size, maybe a name like malloc_allocated_size() (or something a bit 
more compact) would help avoid that confusion, and make it clear that the 
consumer is getting back a commitment and not a hint for future realloc(), 
etc.

Robert N M Watson


More information about the freebsd-arch mailing list