Memory issues in a program is a major pain.

For the last week or so I have been facing a memory cap with lua, more specifically luaJIT. LuaJIT is limited to only 2GB of ram on windows. While in most cases this is more than enough, for path finding and procedural generation much more is needed. In my current project I am generating a city with a river. To make the river I am using A*. A* memory usage increase exponentially as the size of the grid increases. I am hitting the memory limit with a 2000 by 2000 grid. Which is really... limiting

There is two solution to this issue. One is to get access to more memory or two represent the data using less memory. Both solutions would best be done using LuaJIT's FFI module. It allows us to use C code directly in our lua program. Using structs we could reduce the amount of memory our program uses. It would be fairly easy. Well easy in comparison to trying to get access to more memory. With FFI I can use a struct in two ways. One way is to this is to use malloc and manually free the memory. this would side step the GC and the limit. The other way is to just let the GC manage the structs. Which will contribute to the memory limit.

Deciding which to depends on your use case and how much time you have to make a solution. For me I am just going to use FFI structs and have lua GC manage them. It will use less memory then it currently is while not taking me forever to make it.