aboutsummaryrefslogtreecommitdiff
path: root/lmem.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-12-20 16:17:46 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-12-20 16:17:46 -0200
commit737f119187aca3c8f6743ec6e3cfc04e83723180 (patch)
tree4e1bfb4b2bef35dd2acfe2915ab51481cd9ebc16 /lmem.c
parent8980c630bf40e05dad71ded377e3d0f0a17b076c (diff)
downloadlua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.gz
lua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.bz2
lua-737f119187aca3c8f6743ec6e3cfc04e83723180.zip
better control for GC running or stopped
Diffstat (limited to 'lmem.c')
-rw-r--r--lmem.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/lmem.c b/lmem.c
index fd49a789..31c03364 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.78 2010/05/04 18:10:02 roberto Exp roberto $ 2** $Id: lmem.c,v 1.79 2010/05/05 18:49:56 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -79,14 +79,14 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
79 size_t realosize = (block) ? osize : 0; 79 size_t realosize = (block) ? osize : 0;
80 lua_assert((realosize == 0) == (block == NULL)); 80 lua_assert((realosize == 0) == (block == NULL));
81#if defined(HARDMEMTESTS) 81#if defined(HARDMEMTESTS)
82 if (nsize > realosize && !gcstopped(g)) 82 if (nsize > realosize && g->gcrunning)
83 luaC_fullgc(L, 1); /* force a GC whenever possible */ 83 luaC_fullgc(L, 1); /* force a GC whenever possible */
84#endif 84#endif
85 newblock = (*g->frealloc)(g->ud, block, osize, nsize); 85 newblock = (*g->frealloc)(g->ud, block, osize, nsize);
86 if (newblock == NULL && nsize > 0) { 86 if (newblock == NULL && nsize > 0) {
87 api_check(L, nsize > realosize, 87 api_check(L, nsize > realosize,
88 "realloc cannot fail when shrinking a block"); 88 "realloc cannot fail when shrinking a block");
89 if (!gcstopped(g)) { 89 if (g->gcrunning) {
90 luaC_fullgc(L, 1); /* try to free some memory... */ 90 luaC_fullgc(L, 1); /* try to free some memory... */
91 newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 91 newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */
92 } 92 }
@@ -95,8 +95,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
95 } 95 }
96 lua_assert((nsize == 0) == (newblock == NULL)); 96 lua_assert((nsize == 0) == (newblock == NULL));
97 g->totalbytes = (g->totalbytes - realosize) + nsize; 97 g->totalbytes = (g->totalbytes - realosize) + nsize;
98 if (!gcstopped(g)) 98 g->GCdebt += nsize; /* give some credit to garbage collector */
99 g->GCdebt += nsize; /* give some credit to garbage collector */
100#if defined(TRACEMEM) 99#if defined(TRACEMEM)
101 { /* auxiliary patch to monitor garbage collection. 100 { /* auxiliary patch to monitor garbage collection.
102 ** To plot, gnuplot with following command: 101 ** To plot, gnuplot with following command:
@@ -108,9 +107,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
108 if ((total % 200) == 0) { 107 if ((total % 200) == 0) {
109 if (f == NULL) f = fopen(TRACEMEM, "w"); 108 if (f == NULL) f = fopen(TRACEMEM, "w");
110 fprintf(f, "%lu %u %d %d\n", total, 109 fprintf(f, "%lu %u %d %d\n", total,
111 g->totalbytes, 110 g->totalbytes, g->GCdebt, g->gcstate * 1000);
112 gcstopped(g) ? 0 : g->GCdebt,
113 g->gcstate * 1000);
114 } 111 }
115 } 112 }
116#endif 113#endif