[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how do I create a table with known big size?
- From: "Joseph C. Sible" <josephcsible@...>
- Date: Tue, 26 May 2020 13:05:16 -0400
On Tue, May 26, 2020 at 1:04 PM Joseph C. Sible <josephcsible@gmail.com> wrote:
>
> 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
Correction for the record: like lua_createtable, not lua_newtable.
Joseph C. Sible