lua-users home
lua-l archive

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


> Yes, but the performance issue cuts both ways. The most simple 
> way to keep the count in Lua internally would be to 
> add an internal "element_count" variable to each table. 
> However, in that case, for each addition or deletion of an element 
> to th table, you need to update this internal variable. This does not 
> sound like much, but what if you have a data table of 
> thousands of elements?  

It doesn't matter how many elements are in the table. In fact when the
table is huge is exactly when it's MORE important for Lua to own the
size for you so people don't unwittingly iterate over huge tables just
to get their size. Incrementing/decrementing an int is like a couple
machine instructions and is absolutely not even on the performance radar
in terms of all the other stuff going on to add/remove an element from a
table. I would wager you couldn't even measure the perf difference.

Curt