Customizing Lua memory allocation
In the Lua runtime, memory is allocated, reallocated, or deallocated in the heap in the following situations:
- Memory is allocated: This happens when an object is created. Lua needs to allocate a piece of memory to hold it.
- Memory is reallocated: This happens when the size of an object needs to be changed – for example, adding entries to a table when the table has no more pre-allocated space.
- Memory is deallocated: This happens during garbage collection when the object is no longer needed.
In most situations, you do not need to be concerned about this. But sometimes, it is helpful to get an insight into, or customize, the Lua memory allocation. Here are some examples:
- You need to analyze the memory footprint of your Lua objects to find optimization opportunities.
- You need to customize where the memory is allocated. For example, to increase runtime efficiency, you may have a memory pool and you can simply have...