Re: Proposed addition of malloc_size_np()
- From: John-Mark Gurney <gurney_j@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Mar 2006 20:51:49 -0800
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"
- Follow-Ups:
- Re: Proposed addition of malloc_size_np()
- From: Poul-Henning Kamp
- Re: Proposed addition of malloc_size_np()
- References:
- Proposed addition of malloc_size_np()
- From: Jason Evans
- Proposed addition of malloc_size_np()
- Prev by Date: Proposed addition of malloc_size_np()
- Next by Date: Re: Proposed addition of malloc_size_np()
- Previous by thread: Proposed addition of malloc_size_np()
- Next by thread: Re: Proposed addition of malloc_size_np()
- Index(es):
Relevant Pages
- Re: How to release heap memory that is marked as free
... As I said, fragmentation is a very serious problem, and one of the most serious problems
... my allocator was accused of using massive amounts of memory. ... I'm going to
have to re-think the memory allocation that I'm ... process's 'working set'. ...
(microsoft.public.vc.mfc) - Re: [PATCH 00/28] Swap over NFS -v16
... memory they can consume. ... So we need the extra (skb) ... included
in the reserve? ... if the allocation had to dip into emergency reserves, ...
(Linux-Kernel) - Re: Memory leak with CAsyncSocket::Create
... read my essay on how storage allocators work. ... Create method is consuming
system memory that is not released back to ... The memory consumption is either shown as "Mem
Usage" on the Task ... many levels of allocation going ... (microsoft.public.vc.mfc) - 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: OT: C++ overloading operators
... dynamic allocation, no matter how many "clever tricks" are used... ... though
there's enough memory in the system, ... all these "flexible data types" map into
CPU command ... The computing environment is completely ... (comp.dsp)