Re: Proposed addition of malloc_size_np()
- From: John-Mark Gurney <gurney_j@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Mar 2006 13:20:52 -0800
John Baldwin wrote this message on Mon, Mar 27, 2006 at 15:20 -0500:
On Monday 27 March 2006 11:34, Jason Evans wrote:^^^^^^ shall
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
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."
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"
- References:
- Proposed addition of malloc_size_np()
- From: Jason Evans
- Re: Proposed addition of malloc_size_np()
- From: John Baldwin
- Re: Proposed addition of malloc_size_np()
- From: Jason Evans
- Re: Proposed addition of malloc_size_np()
- From: John Baldwin
- Proposed addition of malloc_size_np()
- Prev by Date: Re: Proposed addition of malloc_size_np()
- Next by Date: Re: Proposed addition of malloc_size_np()
- Previous by thread: Re: Proposed addition of malloc_size_np()
- Next by thread: Re: Proposed addition of malloc_size_np()
- Index(es):
Relevant Pages
- Re: malloc
... If I use both the calls ie. malloc and realloc together, how the allocated memory
will be ... Again, an old pointer value, valid for the first allocation of p, will ...
(comp.lang.c) - Re: realloc, copy and VM
... > When you realloc for more size, it may be necessary to allocate a new block, ...
> copy memory and deallocate the old, for example if there is not enough free ... That
*is* extending the original block. ... via lazy allocation and copy-on-write.) ...
(comp.lang.c) - Re: when can realloc fail?
... will the allocation of ptr be freed? ... about what the Standard requires/allows.
... memory pointed to by p, basing the claim on the deallocation ... Don't call
realloc() with the second ... (comp.lang.c) - Re: malloc
... If I use both the calls ie. malloc and realloc together, how the allocated memory
will be ... Again, an old pointer value, valid for the first allocation of p, will ...
(comp.lang.c) - Re: appending elements to an ALLOCATABLE array
... > That's not a realloc. ... this) of addressing more than one pre-allocated
memory locations using ... > As a proposed solution, I don't think what he asked
for works. ... > For pointer allocation, you only need one copy today. ... (comp.lang.fortran)