lua-users home
lua-l archive

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



One thing to be aware of if you are running on a *really* resource constrained system is that you are better off with fewer, bigger, tables. Consider storing 1000 (x,y) pairs. The obvious way to do this is to store 1000 {x,y} tables in an array. However, although it's not as elegant, you are better off storing this as two simple arrays of 1000 elements, one containing the x values, one the y. This second method uses only two tables instead of 1,001.

And yes, the code is FAR less readable. Also, of course, if you do use this method, the whole keys vs indices argument goes away.

--Tim

On Jun 6, 2013, at 2:32 PM, Geoff Smith <spammealot1@live.co.uk> wrote:

The second method sounds like it would be faster, and less memory to store on the Lua side. But I wouldn't be surprised if Lua did some tricks for the hash table example where it optimises its key string storage so it doesn't need to store the key strings "time" and "value" 5000 times. So maybe it would be of similar memory cost, and maybe only slightly slower ?