I've read somewhere on here where someone recommended using Loki's Small Object Allocator for Lua to help improve allocation performance. I read through the section in 'Modern C++ Design' and I think I've got a good enough understand on using Loki for this, with the exception of not using the SmallObject - Lua just wants raw memory, so I took a first stab at using the SmallObjAllocator directly.
The allocations seem like they are working, but everything completely fails once I tried to load a script (either using lua_load() with my own custom reader, or using luaL_loadfile() to read the file directly).
Here's my implementation of the SmallObjAllocator class:
class MySmallAllocator : public Loki::SmallObjAllocator { public: MySmallAllocator( std::size_t pageSize, std::size_t maxObjectSize, std::size_t objectAlignSize ) : Loki::SmallObjAllocator( pageSize, maxObjectSize, objectAlignSize ) { }
virtual ~MySmallAllocator() { } }; static MySmallAllocator alloc_(4096,64,4);
And when I create the Lua state, I give it the allocation function that uses this new allocator:
masterState_ = lua_newstate(customAlloc_, &heap_);
void* customAlloc_( void* ud, void* ptr, size_t osize, size_t nsize ) { // If the new size is zero, we're destroying a block if (nsize == 0) { alloc_.Deallocate( ptr ); ptr = NULL; } // If the original size is zero, then we're creating one else if (0 != nsize && 0 == osize) { ptr = alloc_.Allocate( nsize, false ); } else { alloc_.Deallocate( ptr ); ptr = alloc_.Allocate( nsize, false ); }
return ptr; }
And here I go to load the file:
int result = luaL_loadfile( masterState_, "Global.lua" );
If i have a simple for loop in Global.lua the system never returns from the call to luaL_loaloadfile():
for i=1,100 do
local test = { }
end
What is wrong, how should I diagnose this, and how do I fix it?