lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
Does Lua ever realloc() or malloc() 0 bytes?

Frequently.


What are the expected semantics of:

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

Free the block. (Assuming 'realloc' is Lua allocation function.)

Which is done for us in l_alloc() automatically. The system
specific implementation realloc() is never called in that case.

When nsize is zero, the allocator must return NULL; if osize is not
zero, it should free the block pointed to by ptr.


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

no op (unlike C realloc).

Hmmmm - this should never happen since l_alloc handles that case for
us :-)

Thanks. It's always nice to get one's answers to questions answered
straight from the horse's mouth!

Cheers, Ralph