lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Are there any pointers to doing this?  There's no debug hook for
> allocations; could I add one?  By modifying lmem.c?

Rather than modifying lmem.c... redefine l_free and l_realloc to point to
your own functions.

#define l_free(p,os)
#define l_realloc(p,os,s)

If you define l_free(pointer, oldsize) and l_realloc(pointer, oldsize,
newsize) to refer to your own instrumentation, you can intercept all
allocations and releases in your code to do statistics gathering.

I use the above method to redirect all Lua memory management to a pool-based
system for increased overall Lua performance under Win32. It is convenient
that Lua's code supplies the old size on free, since it allows for memory
management optimization with fixed sized pool allocation schemes.

--
Quinn