lua-users home
lua-l archive

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


On Tue, May 26, 2020 at 12:34 PM Andrea <andrea.l.vitali@gmail.com> wrote:
>
> Let's say I know I need to create a big table and I do not want rehashes to happen when I am filling it.
>
> What is the best way in Lua to create the big table?
>
> Is there any way to create a big table with only the array or only the hash part?
>
> This can be done with the C API but I am wondering if there is way in Lua. It seems not but maybe I missed something.
>
> I can only think about big constructors list in the source code - but there is a limit on how big they can be right?

There's indeed no nice way to preallocate tables from pure Lua source
code. Interestingly, though, the NEWTABLE opcode in Lua bytecode has
support for that just like lua_newtable does; it's just not exposed to
Lua source code except indirectly through table constructors, as you
mentioned.

Joseph C. Sible