lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Enrico Colombini wrote:
I'm considering using Lua on a system offering no realloc(): only malloc() and free().

What loss of performance could I expect by using realloc=free+malloc, assuming the allocator is stupid enough not to immediately recycle the same block when there is enough space?

I'd be more worried about loss of data, unless the semantics

  malloc(new) + memcpy(old to new) + free(old)

Many realloc() implementations do exactly this anyways for
security reasons, but you end up with quite some overhead in
time and memory when the blocks are large, and just time
when they are small.

One problem with the classic realloc() is that you may end up
with quite a bit of heap fragmentation if realloc() is generally
reducing the block by a size which is too small to be reused.

It's the little leftover bits that are killing me in my embedded
application and I'm going to instrument what happens if my
realloc() always does a malloc/copy/free instead of a resize...

Can I ask which platform does not have realloc() ?