Re: Proposed addition of malloc_size_np()



Jason Evans wrote this message on Fri, Mar 24, 2006 at 15:17 -0800:
=== Proposal ===
Add malloc_size_np() to libc, and provide the prototype in malloc_np.h:

size_t
malloc_size_np(const void *ptr);

This function would return the usable size of the allocation pointed to
by ptr, which is always greater than or equal to the size that was
specified in the call to malloc(), calloc(), posix_memalign(), or
realloc(), regardless of allocator implementation. It is up to the
implementation whether the value returned by malloc_size_np() differs
from the size specified during allocation, but the return value must be
consistent across multiple calls for the same allocation.

a) the idea of using memory beyond what you've allocated is bad...
b) it should return the maximum size you can realloc to w/o a copy
of the memory... and then the way you use the extra memory is to
call realloc on the buffer to the value returned by malloc_size_np..

My vote is to never let allocations go outside their area even if
they could... It'll just make new programmers lazy, and ready to
break something...

--
John-Mark Gurney Voice: +1 415 225 5579

"All that I will do, has been done, All that I have, has not."
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"



Relevant Pages