Re: [RFC] how to get the size of a malloc(9) block ?

From: Daniel Nebdal <dnebdal_at_gmail.com>
Date: Sun, 1 Dec 2013 11:55:12 +0100
On Sun, Dec 1, 2013 at 4:04 AM, <dt71_at_gmx.com> wrote:

> John-Mark Gurney wrote, On 12/01/2013 03:20:
>
>  Either it happens rarely, and always doing a realloc won't hurt
>> performance, or it happens often, and then you should be using a larger
>> buffer in the first place..
>>
>
> What if a size-elastic implementation of a dynamic data structure would be
> able to adjust to the malloc implementation, such as agreeing to allocate
> regions of size (2^k - 8)? Much like the use of getpagesize() (yes, I know
> it's not part of a technical standard).
>
>

That could alternatively be solved by having an "if I ask for N bytes right
now, how large would the block be" - API that doesn't promise too much.
Call it something like "malloc_suggest_size(size_t minsize) ", and make the
description something like ...  "return the largest number of bytes that
would not allocate a larger block of memory than the provided minsize, in
the current memory situation", plus some veiled threats about not using
this value to do anything fancy with pointers to already-allocated memory.

-- 
Daniel Nebdal
Received on Sun Dec 01 2013 - 09:55:15 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:44 UTC