For a serializing system, I need to allocate buffers to write data into. The size needed is not known in advance, so the basic pattern is to malloc
N
bytes and use realloc
if more is needed. The size of N
would be large enough to accommodate most objects, making reallocation rare.
This made me think that there is probably an optimal initial amount of bytes that malloc
can satisfy more easily than others. I'm guessing somewhere close to pagesize
, although not necessarily exactly if malloc
needs some room for housekeeping.
Now, I'm sure it is a useless optimization, and if it really mattered, I could use a pool, but I'm curious; I can't be the first programmer to think give me whatever chunk of bytes is easiest to allocate as a start. Is there a way to determine this?
Any answer for this that specifically applies to modern GCC/G++ and/or linux will be accepted.