lua-users home
lua-l archive

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

I think this should not be exposed, unless you tie your Lua program to a specific implementation and version. This is basically used only in the current implementation just to allow fast startup of the existing engine but this API should not even be considered "stable" and is only needed for internal use. Any later version of Lua could change it, providing other tuning parameters (and for now there's no official stable API to tune a specific implementation, it would require IMHO defining a new type for tuning parameters, using a set of key/value property pairs, with keys inside some namespace targeting a specific class of implementations. These will only be used as hints, and not requirements, the implementations are then free to ignore these parameters.

Le dim. 11 oct. 2020 à 17:24, Jonathan Goble <> a écrit :
On Sun, Oct 11, 2020 at 6:20 AM Ranier Vilela <> wrote:
Em dom., 11 de out. de 2020 às 04:58, 孙世龙 sunshilong <> escreveu:
Hi, list

Is it possible to pre-allocate a table with a specific size(i.e.
pre-allocating the max memory that may be used by a table)?

As per the book(Programming in Lua 4th Edition, page 37), which says that:
To represent a conventional array or a list, we simply use a table
with integer keys. There is neither a way
nor a need to declare a size.
As far as I know, there's no way.
Even the Lua C API is limited by int (MAX_INT).

In the C API, there is lua_createtable [1]:

"Parameter narr is a hint for how many elements the table will have as a sequence; parameter nrec is a hint for how many other elements the table will have. Lua may use these hints to preallocate memory for the new table. This preallocation may help performance when you know in advance how many elements the table will have."

This is not exposed on the Lua side, though it would be trivial to write a small extension module to make it available.