lua-users home
lua-l archive

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


On 19 December 2014 at 13:08, <andre@leiradella.com> wrote:
My lua_Alloc function is:

static void* LuaAllocator( void* ud, void* ptr, size_t osize, size_t nsize )
{
  linear_allocator_t* lalloc = (linear_allocator_t*)ud;
  void* nptr = 0;

  if ( nsize != 0 )
  {
    if ( osize < nsize )
    {
      nptr = linear_allocator_malloc( lalloc, nsize );
    }
    else
    {
      nptr = ptr;
    }
  }

  printf( "ptr=%p osize=%4u nsize=%4u nptr=%p used=%.8u\n", ptr, osize, nsize, nptr, lalloc->current_offset );
  fflush( stdout );
  return nptr;
}

If ptr is NULL, osize is the type of the thing being allocated.