lua-users home
lua-l archive

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


Hi,  Robert Burke

Thank you for your clarification.

>As discussed previously on the mailing list, you'll cause tables'
>contents to be copied to a new backing array and rehashed just by
>adding and removing elements while keeping the table a fixed size.
How to keep the table a fixed size?
I found that it seems that there are two related problems:
1. How to pre-allocate a fixed size table in Lua?
    I find it is only possible on the C side with this function:
    void lua_createtable (lua_State *L, int narr, int nrec);
    (for details, see
    https://stackoverflow.com/questions/124455/how-do-you-pre-size-an-array-in-lua)

2.There's no trivial way to get the size of a table(for details, see
https://stackoverflow.com/questions/2461932/is-there-a-simple-way-to-get-the-memory-usage-of-a-lua-table.)

Thank you for your attention to this matter.
Best regards
Sunshilong

On Fri, Sep 25, 2020 at 9:40 PM Robert Burke <sharpobject@gmail.com> wrote:
>
> On Thu, Sep 24, 2020 at 10:35 PM Gé Weijers <ge@weijers.org> wrote:
> > Growing a table is the operation that would cause significant delays when the table is large enough. You would have to keep sizes small or fixed to guarantee constant time operations.
>
> As discussed previously on the mailing list, you'll cause tables'
> contents to be copied to a new backing array and rehashed just by
> adding and removing elements while keeping the table a fixed size.