Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Mar 2006 20:51:49 -0800
From:      John-Mark Gurney <gurney_j@resnet.uoregon.edu>
To:        Jason Evans <jasone@FreeBSD.org>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: Proposed addition of malloc_size_np()
Message-ID:  <20060325045149.GA7001@funkthat.com>
In-Reply-To: <44247DF1.8000002@FreeBSD.org>
References:  <44247DF1.8000002@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060325045149.GA7001>