lua-users home
lua-l archive

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


> So, as PiL says 'osize' is always valid, I guess adding this line at the 
> top of a copy of l_alloc() should keep track of allocated memory, 
> assuming allocations always succeed:
> 
>   currentlyAllocated += (nsize - osize);
> 
> Is that correct or are there caveats?

That's correct for Lua 5.1 but not for 5.2 because the manual says:

   When ptr is NULL, osize encodes the kind of object that Lua is allocating.
   http://www.lua.org/manual/5.2/manual.html#lua_Alloc

So you need to handle the case ptr==NULL separately if you want to track
total memory use. Or if you're not interested in the info osize provides,
just do
	osize = (ptr==NULL) ? 0 : osize;