lua table size in memory

i found this link : http://wowwiki.wikia.com/Lua_object_memory_sizes
with interesting info.

That’s an interesting read, thanks for sharing

thank you for the link

Thanks for sharing @Jmv38

I have been running into memory issues as my array of a class gets bigger. This document is quite useful, but I am wondering how does memory for codea class works?

For example, I have an object class in codea. It has a name (string), some variables (integer), and an integer array. What is the best way to optimise memory? Should I group my variables into say a vec4?

Wow, that must be a big table. What kind of size are we talking about? Have you used collectgarbage to check memory usage?

I doubt that packing variables into a vec4 would help.

Thanks @yojimbo2000. I have indeed used collectgarbage and it cannot help. The optmisation has to come from table/class optimisation. I have a few different classes (monster , item , effects, objects, terrain), each with an average of a thousand entries, each class about 30 different attributes. On xcode debugger, this is the main memory gobbler. The drawing meshes are separate and only allocated when drawing.

For the less commonly used stuff in the class I could of course store these information into an io text file to be read as needed. (Btw, readtext not working is really a pain). That can release some memory which I am hoping to allocate for the drawing meshes to help boost FPS. I am thinking of going down this route.

Any other ideas are welcomed!

@zapaper What problems are you having with readText. I just tried reading a 3.1 MB text file and had no problem. It read the file and printed the size (3,151,541) in the blink of an eye.

@dave1707 re: readText, I think @zapaper means in Xcode. It works for assets that you include in Xcode, but not for things you create programmatically and save with saveText.
@zapaper have you tried readLocalData and saveLocalData? Those definitely work in Xcode.

If you have lots of flags, you could try packing those into a variable using Lua 5.3 bitwise operations. But that’s a tactic from the 8/16-bit days, I didn’t realise anyone still had to do it now! I think loading data into memory as it’s needed is the way to go here.

You might also try breaking some of your tables into sub tables, eg if for example, there are certain monsters in different parts of the terrain, you could have a table of monsters for each part and load it as required

Thanks for the advice, will do some read up on lua 5.3 bit wise operation. Yes, I meant savetext/readtext in xcode/app, not codea runtime.

I would try readLocalData saveLocalData for data persistence first before bit wise flags. Having vast areas of the game world in memory all at once sounds problematic. Or look at procedural generation, eg perlin noise / fibunacci sequence etc to generate object data when it’s needed. Eg among those thousands of monsters there must be a lot of overlap. I don’t see why you need 1000s of instances. Remember that the original Elite fit a universe of 1000s of star systems into a few kilobytes using procedural generation (fibunacci I believe)