aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-04-29 15:53:53 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-04-29 15:53:53 -0300
commit21c9ebf4a9891786d5683537868cc348340ca89d (patch)
treec0e0eb45ac121869ca62ee420863f17de6463d6e
parent4fb77c430869e4a6c95fd00cd6a9b9c383d95e71 (diff)
downloadlua-21c9ebf4a9891786d5683537868cc348340ca89d.tar.gz
lua-21c9ebf4a9891786d5683537868cc348340ca89d.tar.bz2
lua-21c9ebf4a9891786d5683537868cc348340ca89d.zip
new algotithm to adjust garbage collection: it tries to adapt gc calls
so that it collects half of the total objects when it is called.
-rw-r--r--table.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/table.c b/table.c
index 31ec0ac1..cb9a6a2c 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.51 1996/03/21 18:54:29 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.52 1996/04/22 18:00:37 roberto Exp $";
7 7
8#include "mem.h" 8#include "mem.h"
9#include "opcode.h" 9#include "opcode.h"
@@ -27,8 +27,7 @@ Word lua_nconstant = 0;
27static Long lua_maxconstant = 0; 27static Long lua_maxconstant = 0;
28 28
29 29
30#define GARBAGE_BLOCK 1024 30#define GARBAGE_BLOCK 50
31#define MIN_GARBAGE_BLOCK (GARBAGE_BLOCK/2)
32 31
33static void lua_nextvar (void); 32static void lua_nextvar (void);
34 33
@@ -209,14 +208,13 @@ Long luaI_collectgarbage (void)
209 208
210void lua_pack (void) 209void lua_pack (void)
211{ 210{
212 static Long block = GARBAGE_BLOCK; /* when garbage collector will be called */ 211 static unsigned long block = GARBAGE_BLOCK;
213 static Long nentity = 0; /* counter of new entities (strings and arrays) */ 212 static unsigned long nentity = 0; /* total of strings, arrays, etc */
214 Long recovered = 0; 213 unsigned long recovered = 0;
215 if (nentity++ < block) return; 214 if (nentity++ < block) return;
216 recovered = luaI_collectgarbage(); 215 recovered = luaI_collectgarbage();
217 nentity = 0; /* reset counter */ 216 block = block*2*(1.0 - (float)recovered/nentity);
218 block=(16*block-7*recovered)/12; /* adapt block size */ 217 nentity -= recovered;
219 if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK;
220} 218}
221 219
222 220