Re: Is realloc good form ?
On Oct 18, 1:28 pm, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
> It depends. realloc will often be clever enough to realise that it can
> just use the previous block of data without any change. So if you pass
> in the same Size or similar Size values (like 10000, 10001, 9999) it
> will be fast. However, if a new block is allocated, all the data will
> be copied from the previous block to the new block, because that is
> what realloc does. That might be quite wasteful.
realloc tries not to copy the data, just resize the available block of
memory.
> Note that realloc() *may* move the memory allocation resulting in a different return value than ptr.
|