Lua runs out of memory -
i've written complicated lua script uses lua sockets library. reads list of files disk, sorts them date , sends them http process. number of files on disk around 65k.the memory usage in taskmanager doesn't exceed 200mb.
after quite while script returns:
lua: not enough memory
i print out current gc count @ points , never goes above 110mb
local freemem = collectgarbage('count'); print("gc count : " .. freemem/1024 .. " mb");
this on 32 bit windows machine.
what's best way diagnose this?
all memory goes through single lua_alloc function. takes form of:
typedef void* (*lua_alloc) (void* ud, void* ptr, size_t oszie, size_t nsize);
all allocations, reallocations , frees go through this. documentation can found @ this web page. can write own track memory operations. example,
void* myalloc (void* ud, void* ptr, size_t osize, size_t nsize) { (void)ud; (void)osize; // not used if (nsize == 0) { free(ptr) tracksubtract(osize); return null; } else { void* p = realloc(ptr,nsize); tracksubtract(osize); if (p) trackadd(nsize); return p; } }
you can write trackadd() , tracksubtract() functions whatever want: output log; adjust counter , on.
to use new function pass pointer when create lua state:
lua_state* l = lua_newstate(&myalloc,0);
the documentation lua_newstate found here.
good luck.
Comments
Post a Comment