lua-users home
lua-l archive

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


On Mon, Apr 6, 2009 at 4:14 PM, Matthew Wild <mwild1@gmail.com> wrote:
> On Mon, Apr 6, 2009 at 11:41 PM, Fabien <fleutot+lua@gmail.com> wrote:
>> There could be many definitions of "large tables", so you have to pick one,
>> and implement the corresponding algorithm. For instance, what's the size of
>> table { _G, _G } ?
>>
>
> Obviously the size of the allocated table's header (no idea how Lua
> represents this internally, so sorry if I'm mis-using terms) plus the
> length of 2 references to another table (I presume all such references
> are of a fixed size).

So, you'd consider it the same size as

table { string.rep("x", 10000000}, _G }

?

In that case, you appear to only care about number of entries in a
table. You can count the size of the array part with
  #t

and use pairs() to iterate the table and find how many entries total,
then subtract.

Actual memory should be a small linear factor of that, you don't need
byte usage, just tables that are excessively large, or so it sounds.

Cheers,
Sam