Hey Rob,I do have a couple of technical questions that I hope you (or the Corona team can answer)
- Is there anyway of getting a break down of lua memory used (particularly arrays and metatables)? Texture memory is fairly easy to calculate (based on graphic size in 32bit). For example, My game uses 100mb lua memory as a baseline for an empty city of 130x130 tiles. Each tile is represented in memory as a metatable that contains multiple displayGroups, variables, arrays and functions. This essentially makes a 4D array of data that defines my game world.
With a playable city the texture memory can easily reach another 50mb (with non 2x graphics, upwards of 200MB with HD graphics) and this is a problem for 512mb devices and often means the app is terminated by the OS.
I did try a paid corona profiler but it just kept falling over (out of memory exceptions) and crashing my laptop. Something native like getMemoryUsed(object) would be really great!
- My game uses multiple 2D arrays of boolean values because in my experience (in multiple languages) this is faster in random access than larger 3D arrays when accessed continually (similar to unrolling the loop). This also makes the code more readable as I can create an array called isTileARoad and then access it if isTileARoad[x][y] then … end to quickly ascertain if the tile at x,y is a road, etc.
But in lua is this more efficient; scan multiple simple 2D boolean arrays or a more complex 3D array aggregating these values? Also, which is more memory efficient in Corona, 5 x 2D arrays or a 3D array where the 3rd index contains the 5 boolean values?
i.e.
if array1[x][y] and array2[x][y] then DoSomething end
or
if array[x][y].value1 and array[x][y].value2 then DoSomething end
- I’ve noticed that if I leave my game running without any activity other than my enterFrame() listener then memory creeps up. In the time it has taken to write this email my lua memory has gone from 103mb to 132mb. I do declare a few local variables in my enterFrame() so I assume the memory creep is because garbage collection is not clearing them down even though they have gone out of scope?
There is no load as I am running at 30fps (my laptop could easily sustain 120fps) so when does garbage collection kick in? I thought it was on spare CPU cycles or is it only when you call collectgarbage()?
I appreciate these are probing questions but I am trying to understand Corona at a low level so I can optimise my code as much as possible!
Thanks
Adrian


