lua-users home
lua-l archive

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

Roberto Ierusalimschy wrote:
It turns out that realloc() is the only library function that is
called, and my implementation of realloc() calls malloc() if the
pointer to the original data is NULL.

First you should check whether the new size is not zero. (malloc(0) does
allocate memory on some systems...)

Does Lua ever realloc() or malloc() 0 bytes?

As Lua sends all memory requests through realloc(ptr,size) with the
assumption that a NULL ptr means allocate me a new block...

What are the expected semantics of:

1. realloc() an existing block to a size of 0 bytes?
2. realloc() a new block to a size of 0 bytes?

I have instrumented my code to see what the typical size range of
malloc()/realloc()/free() requests is and I see lots of requests in
the 32 to 128 byte size. I don't see any requests in the 0 bytes size.

I'm wondering if my heap is getting horribly fragmented because
my realloc() tends to "break off" the higher memory and put it
in the free list if a block is being downsized.

I think that I may try to do something like limit the block sizes
to some minimal value, and possibly try to find a new block EVERY
time a block is actually reallocated to avoid fragmenting the small
memory blocks.