diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-23 14:26:37 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-23 14:26:37 -0200 |
commit | 907368ead5978b689a97118b75e89a2095122530 (patch) | |
tree | ed428793e87ab4a3c8de49be5586878af54c8d34 /lgc.c | |
parent | 81489beea1a201b58dba964b6bbfd263f3683f25 (diff) | |
download | lua-907368ead5978b689a97118b75e89a2095122530.tar.gz lua-907368ead5978b689a97118b75e89a2095122530.tar.bz2 lua-907368ead5978b689a97118b75e89a2095122530.zip |
GC now considers an "estimate" of object size, instead of just the number
of objects.
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.3 1997/09/26 16:46:20 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.4 1997/10/16 10:59:34 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -148,7 +148,6 @@ static GCnode *listcollect (GCnode *l) | |||
148 | next->next = frees; | 148 | next->next = frees; |
149 | frees = next; | 149 | frees = next; |
150 | next = l->next; | 150 | next = l->next; |
151 | --luaO_nentities; | ||
152 | } | 151 | } |
153 | l = next; | 152 | l = next; |
154 | } | 153 | } |
@@ -252,7 +251,7 @@ static void call_nilIM (void) | |||
252 | 251 | ||
253 | #define GARBAGE_BLOCK 150 | 252 | #define GARBAGE_BLOCK 150 |
254 | 253 | ||
255 | long luaC_threshold = GARBAGE_BLOCK; | 254 | unsigned long luaC_threshold = GARBAGE_BLOCK; |
256 | 255 | ||
257 | 256 | ||
258 | static void markall (void) | 257 | static void markall (void) |
@@ -266,7 +265,7 @@ static void markall (void) | |||
266 | 265 | ||
267 | long lua_collectgarbage (long limit) | 266 | long lua_collectgarbage (long limit) |
268 | { | 267 | { |
269 | long recovered = luaO_nentities; /* to subtract luaM_new value after gc */ | 268 | unsigned long recovered = luaO_nblocks; /* to subtract nblocks after gc */ |
270 | Hash *freetable; | 269 | Hash *freetable; |
271 | TaggedString *freestr; | 270 | TaggedString *freestr; |
272 | TProtoFunc *freefunc; | 271 | TProtoFunc *freefunc; |
@@ -277,24 +276,25 @@ long lua_collectgarbage (long limit) | |||
277 | freetable = (Hash *)listcollect(&luaH_root); | 276 | freetable = (Hash *)listcollect(&luaH_root); |
278 | freefunc = (TProtoFunc *)listcollect(&luaF_root); | 277 | freefunc = (TProtoFunc *)listcollect(&luaF_root); |
279 | freeclos = (Closure *)listcollect(&luaF_rootcl); | 278 | freeclos = (Closure *)listcollect(&luaF_rootcl); |
280 | recovered = recovered-luaO_nentities; | 279 | luaC_threshold *= 4; /* to avoid GC during GC */ |
281 | /*printf("==total %ld coletados %ld\n", luaO_nentities+recovered, recovered);*/ | 280 | hashcallIM(freetable); /* GC tag methods for tables */ |
282 | luaC_threshold = (limit == 0) ? 2*luaO_nentities : luaO_nentities+limit; | 281 | strcallIM(freestr); /* GC tag methods for userdata */ |
283 | hashcallIM(freetable); | 282 | call_nilIM(); /* GC tag method for nil (signal end of GC) */ |
284 | strcallIM(freestr); | ||
285 | call_nilIM(); | ||
286 | luaH_free(freetable); | 283 | luaH_free(freetable); |
287 | luaS_free(freestr); | 284 | luaS_free(freestr); |
288 | luaF_freeproto(freefunc); | 285 | luaF_freeproto(freefunc); |
289 | luaF_freeclosure(freeclos); | 286 | luaF_freeclosure(freeclos); |
290 | luaM_clearbuffer(); | 287 | luaM_clearbuffer(); |
288 | recovered = recovered-luaO_nblocks; | ||
289 | /*printf("==total %ld coletados %ld\n", luaO_nblocks+recovered, recovered);*/ | ||
290 | luaC_threshold = (limit == 0) ? 2*luaO_nblocks : luaO_nblocks+limit; | ||
291 | return recovered; | 291 | return recovered; |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | void luaC_checkGC (void) | 295 | void luaC_checkGC (void) |
296 | { | 296 | { |
297 | if (luaO_nentities >= luaC_threshold) | 297 | if (luaO_nblocks >= luaC_threshold) |
298 | lua_collectgarbage(0); | 298 | lua_collectgarbage(0); |
299 | } | 299 | } |
300 | 300 | ||