Re: Tracing Memory Grabbers
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Tracing Memory Grabbers
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: 2012年3月16日 10:48:55 -0300
> 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;