GC back to controling pace counting bytes

Memory is the resource we want to save. Still to be reviewed again.
This commit is contained in:
Roberto Ierusalimschy
2024-09-19 19:02:14 -03:00
parent b443145ff3
commit ddfa1fbccf
11 changed files with 247 additions and 202 deletions

8
lmem.c
View File

@@ -151,7 +151,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) {
global_State *g = G(L);
lua_assert((osize == 0) == (block == NULL));
callfrealloc(g, block, osize, 0);
g->GCtotalbytes -= osize;
g->GCdebt += cast(l_mem, osize);
}
@@ -181,10 +181,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
if (l_unlikely(newblock == NULL && nsize > 0)) {
newblock = tryagain(L, block, osize, nsize);
if (newblock == NULL) /* still no memory? */
return NULL; /* do not update 'GCtotalbytes' */
return NULL; /* do not update 'GCdebt' */
}
lua_assert((nsize == 0) == (newblock == NULL));
g->GCtotalbytes += nsize - osize;
g->GCdebt -= cast(l_mem, nsize) - cast(l_mem, osize);
return newblock;
}
@@ -209,7 +209,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) {
if (newblock == NULL)
luaM_error(L);
}
g->GCtotalbytes += size;
g->GCdebt -= cast(l_mem, size);
return newblock;
}
}