summaryrefslogtreecommitdiff
path: root/table.c
diff options
context:
space:
mode:
Diffstat (limited to 'table.c')
-rw-r--r--table.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/table.c b/table.c
index 1d6afbfc..86266a96 100644
--- a/table.c
+++ b/table.c
@@ -3,10 +3,11 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.67 1997/04/06 14:08:08 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.68 1997/04/07 14:48:53 roberto Exp roberto $";
7 7
8#include "luamem.h" 8#include "luamem.h"
9#include "auxlib.h" 9#include "auxlib.h"
10#include "func.h"
10#include "opcode.h" 11#include "opcode.h"
11#include "tree.h" 12#include "tree.h"
12#include "hash.h" 13#include "hash.h"
@@ -176,32 +177,43 @@ static void call_nilIM (void)
176** Garbage collection. 177** Garbage collection.
177** Delete all unused strings and arrays. 178** Delete all unused strings and arrays.
178*/ 179*/
179Long luaI_collectgarbage (void) 180static long gc_block = GARBAGE_BLOCK;
181static long gc_nentity = 0; /* total of strings, arrays, etc */
182
183static void markall (void)
180{ 184{
181 Long recovered = 0;
182 lua_travstack(lua_markobject); /* mark stack objects */ 185 lua_travstack(lua_markobject); /* mark stack objects */
183 lua_travsymbol(lua_markobject); /* mark symbol table objects */ 186 lua_travsymbol(lua_markobject); /* mark symbol table objects */
184 luaI_travlock(lua_markobject); /* mark locked objects */ 187 luaI_travlock(lua_markobject); /* mark locked objects */
185 luaI_travfallbacks(lua_markobject); /* mark fallbacks */ 188 luaI_travfallbacks(lua_markobject); /* mark fallbacks */
186 luaI_hashcallIM(); 189}
187 luaI_strcallIM(); 190
191
192static void lua_collectgarbage (void)
193{
194 long recovered = 0;
195 Hash *freetable;
196 TaggedString *freestr;
197 TFunc *freefunc;
198 markall();
199 freetable = luaI_hashcollector(&recovered);
200 freestr = luaI_strcollector(&recovered);
201 freefunc = luaI_funccollector(&recovered);
202 gc_block = 2*(gc_block-recovered);
203 gc_nentity -= recovered;
204 luaI_hashcallIM(freetable);
205 luaI_strcallIM(freestr);
188 call_nilIM(); 206 call_nilIM();
189 luaI_invalidaterefs(); 207 luaI_hashfree(freetable);
190 recovered += lua_strcollector(); 208 luaI_strfree(freestr);
191 recovered += lua_hashcollector(); 209 luaI_funcfree(freefunc);
192 recovered += luaI_funccollector();
193 return recovered;
194} 210}
195 211
212
196void lua_pack (void) 213void lua_pack (void)
197{ 214{
198 static unsigned long block = GARBAGE_BLOCK; 215 if (gc_nentity++ >= gc_block)
199 static unsigned long nentity = 0; /* total of strings, arrays, etc */ 216 lua_collectgarbage();
200 unsigned long recovered = 0;
201 if (nentity++ < block) return;
202 recovered = luaI_collectgarbage();
203 block = 2*(block-recovered);
204 nentity -= recovered;
205} 217}
206 218
207 219