lua-users home
lua-l archive

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

> With the 'actual' lua (5.1) you can track malloc calls, see new function
> lua_newstate() where you can give an own malloc function.

Yes, see the attached file for an example.
In Lua 5.0, you can build Lua with your own allocator by changes 2 defines
in lmem.c.
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
  static size_t total=0;
  static int time=0;
  void *optr=ptr;
  if (nsize == 0) {
    printf(">>> %p %p %8d - T=%d O=%d N=%d\n",ptr,optr,time,total,osize,nsize);
    return NULL;
  else {
    ptr=realloc(ptr, nsize);
    printf(">>> %p %p %8d %c T=%d O=%d N=%d\n",ptr,optr,time,osize==0?'+':'=',total,osize,nsize);
    return ptr;
    if (time==480) abort();