Proposed addition of malloc_size_np()
John-Mark Gurney
gurney_j at resnet.uoregon.edu
Mon Mar 27 21:20:54 UTC 2006
John Baldwin wrote this message on Mon, Mar 27, 2006 at 15:20 -0500:
> On Monday 27 March 2006 11:34, Jason Evans wrote:
> > Following is what I've written for the malloc(3) man page:
> > ----
> > The malloc_usable_size() function returns the usable size of the
> > allocation pointed to by ptr. The return value may be larger than the
> > size that was requested during allocation. malloc_usable_size() is not
> > intended as a mechanism for in-place realloc(), though it can be abused
> > that way; rather it is primarily provided as a tool for introspection
> > purposes. Any discrepancy between the requested allocation size and the
> > size reported by malloc_usable_size() should not be depended on, since
> > such behavior is entirely implementation-dependent.
> > ----
>
> I would word it stronger: "malloc_usable_size() should not be used as a
^^^^^^ shall
> mechanism for in-place realloc(). It is provided solely as a tool for
> introspection purposes."
should is just a suggestion, it isn't strong enough.. I would also
hope that the appropriate test cases are added so that any uses of
memory beyond the allocated sizes (and returned by usable_size), are
ensured not to have been touched, and that we abort() in cases that
someone used memory outside their allocation size...
As long as it returns a value that shall not extend the allocation size
beyond what was allocated by realloc/malloc/calloc, then it's fine...
If it requires a realloc in order to use the additional space, then I'm
fine with it...
I wouldn't mind an implied behavior that you can do a realloc to
malloc_usable_size and it shall not incure a copy.. it'd be useful
temp buffers that you grow so you can use the max of the allocated
space, instead of waste a bit of unalloced memory...
--
John-Mark Gurney Voice: +1 415 225 5579
"All that I will do, has been done, All that I have, has not."
More information about the freebsd-arch
mailing list