lua-users home
lua-l archive

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

> Is there a good reason for this style of constantly reallocating very small
> chunks of memory?

Yes. This a standard practice to manipulate variable-sized arrays. You
start with a small array (because Lua tries to keep a small footprint,
this initial size is frequently zero) and doubles its size when
necessary. (Doubling the size allows the amortized cost for insertions
to be constant.)

> Maybe something to do with low memory footprint etc?

Only the fact that we start from zero.

> Is it something we might see changed in future versions of Lua?

I don't think so. Lua has used that kind of structures since version 1.0,
and it has proved quite appropriate.

Can you be more specific about your problem? Do you have real performance
problems with these reallocs? Can you tell which reallocs are causing
your problems?

-- Roberto