lua-users home
lua-l archive

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

I recently needed to implement a 3 dimensional table to store game map
data. The map is 128x128 tiles in size, and has 8 layers per tile.
Initially I used a naive implementation like map[x][y][layer]=value,
but this requires in excess of 2^14 tables, which eats a considerable
amount of memory, and takes a very noticeable amount of time to
garbage collect. A revised implementation along the lines of map[x *
1024 + y * 8 + layer]=value eliminated the long GC pause when the map
was unloaded (sure, incremental garbage collection helps, but when the
app is closed by the user, the GC has to run fully, and the end result
was a long lag between the user pressing the close button, and the app
actually closing).

On Tue, Oct 6, 2009 at 2:31 PM, steve donovan <> wrote:
> On Tue, Oct 6, 2009 at 3:23 PM, Francesco Abbate
> <> wrote:
>> Hi all,
>> as far as I know is better to use unidimensional table to implement
>> multidimensional array (like in C). Here an example that should do the
>> affair:
> I seriously doubt that all these function calls & arithmetic would
> beat a few table lookups!