lua-users home
lua-l archive

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


Hi, Matthew Wild

>However in most applications if there are objects that are referenced
>by the table (and possibly *only* by the table) you likely want to
>include the size of those objects too.
Could you please explain that in simpler words?

Do you mean something like this:
subTable1 = {};
subTable2 = {};

tabTop = {};
tabTop[1] = subTable1;
tabTop[2] = subTable2;
When I want to know the memory size used by tabTop, I need to iterate
through each sub table?

But the table is very simple, e.g:
simTab={};
simTab["score"] = 100;
simTab["name"] = "Tom";
the module aforementioned could directly figure out the memory size
used by simTab.

Looking forward to hearing from you.
Best wishes
Sunshilong
On Sun, Sep 27, 2020 at 6:51 PM Matthew Wild <mwild1@gmail.com> wrote:
>
> Hi,
>
> On Sun, 27 Sep 2020 at 02:42, 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> >
> > Hi, list
> >
> > Is there a (simple) way to get the memory usage of a Lua object (e.g table)?
>
> Simple? No :)
>
> But yes, you can use this module:
> https://luarocks.org/modules/siffiejoe/getsize to tell you the size of
> the table's internal data structures.
>
> However in most applications if there are objects that are referenced
> by the table (and possibly *only* by the table) you likely want to
> include the size of those objects too.
>
> > I'd like to find out how much memory a Lua table is using - without
> > iterating through the table contents and counting up the usage.