diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-11-03 16:37:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-11-03 16:37:13 -0300 |
commit | 76953316d1283ab6324b59b914ef53a521408444 (patch) | |
tree | 41d34e962db7c645bd56f2dc688fe110d5df46a6 /lgc.c | |
parent | 3d2bd1359d17228b62752f6edae86b6a1579c6d4 (diff) | |
download | lua-76953316d1283ab6324b59b914ef53a521408444.tar.gz lua-76953316d1283ab6324b59b914ef53a521408444.tar.bz2 lua-76953316d1283ab6324b59b914ef53a521408444.zip |
Added a counter of the total number of existing objects
It may simplify the control of the garbage collector.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -259,6 +259,7 @@ GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, size_t offset) { | |||
259 | global_State *g = G(L); | 259 | global_State *g = G(L); |
260 | char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); | 260 | char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); |
261 | GCObject *o = cast(GCObject *, p + offset); | 261 | GCObject *o = cast(GCObject *, p + offset); |
262 | g->totalobjs++; | ||
262 | o->marked = luaC_white(g); | 263 | o->marked = luaC_white(g); |
263 | o->tt = tt; | 264 | o->tt = tt; |
264 | o->next = g->allgc; | 265 | o->next = g->allgc; |
@@ -768,6 +769,7 @@ static void freeupval (lua_State *L, UpVal *uv) { | |||
768 | 769 | ||
769 | 770 | ||
770 | static void freeobj (lua_State *L, GCObject *o) { | 771 | static void freeobj (lua_State *L, GCObject *o) { |
772 | G(L)->totalobjs--; | ||
771 | switch (o->tt) { | 773 | switch (o->tt) { |
772 | case LUA_VPROTO: | 774 | case LUA_VPROTO: |
773 | luaF_freeproto(L, gco2p(o)); | 775 | luaF_freeproto(L, gco2p(o)); |