Date: Mon, 27 Mar 2006 13:20:52 -0800 From: John-Mark Gurney <gurney_j@resnet.uoregon.edu> To: John Baldwin <jhb@freebsd.org> Cc: Vasil Dimov <vd@freebsd.org>, Robert Watson <rwatson@freebsd.org>, Jason Evans <jasone@freebsd.org>, freebsd-arch@freebsd.org Subject: Re: Proposed addition of malloc_size_np() Message-ID: <20060327212052.GK7001@funkthat.com> In-Reply-To: <200603271520.11381.jhb@freebsd.org> References: <44247DF1.8000002@FreeBSD.org> <200603271110.02917.jhb@freebsd.org> <44281421.3060401@FreeBSD.org> <200603271520.11381.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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."
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060327212052.GK7001>
