new way to control GC speed

This commit is contained in:
Roberto Ierusalimschy
2010-04-29 14:35:10 -03:00
parent 5a7a0c72d8
commit 3410dcd375
2 changed files with 26 additions and 16 deletions

11
lmem.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lmem.c,v 1.74 2009/12/16 16:42:58 roberto Exp roberto $
** $Id: lmem.c,v 1.75 2010/04/02 14:37:41 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -79,13 +79,14 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
size_t realosize = (block) ? osize : 0;
lua_assert((realosize == 0) == (block == NULL));
#if defined(HARDMEMTESTS)
if (nsize > realosize && g->GCthreshold != MAX_LUMEM)
if (nsize > realosize && !gcstopped(g))
luaC_fullgc(L, 1); /* force a GC whenever possible */
#endif
newblock = (*g->frealloc)(g->ud, block, osize, nsize);
if (newblock == NULL && nsize > 0) {
lua_assert(nsize > realosize); /* cannot fail when shrinking a block */
if (g->GCthreshold != MAX_LUMEM) {
api_check(L, nsize > realosize,
"realloc cannot fail when shrinking a block");
if (!gcstopped(g)) {
luaC_fullgc(L, 1); /* try to free some memory... */
newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
}
@@ -94,6 +95,8 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
}
lua_assert((nsize == 0) == (newblock == NULL));
g->totalbytes = (g->totalbytes - realosize) + nsize;
if (!gcstopped(g)) /* new object? */
g->GCdebt += nsize; /* give some credit to garbage collector */
#if defined(TRACEMEM)
{ /* auxiliar patch to monitor garbage collection.
** To plot, gnuplot with following command: