Browse Source

new API function to force garbage collection.

Roberto Ierusalimschy 28 years ago
parent
commit
e1249970c2
3 changed files with 18 additions and 8 deletions
  1. 7 1
      inout.c
  2. 4 1
      lua.h
  3. 7 6
      table.c

+ 7 - 1
inout.c

@@ -5,7 +5,7 @@
 ** Also provides some predefined lua functions.
 */
 
-char *rcs_inout="$Id: inout.c,v 2.57 1997/04/06 14:14:27 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.58 1997/04/15 17:32:47 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -310,6 +310,11 @@ static void rawsettable (void)
 }
 
 
+static void luaI_collectgarbage (void)
+{
+  lua_pushnumber(lua_collectgarbage(luaL_opt_number(1, 0)));
+}
+
 
 /*
 ** Internal functions
@@ -320,6 +325,7 @@ static struct {
 } int_funcs[] = {
   {"assert", luaI_assert},
   {"call", luaI_call},
+  {"callgc", luaI_collectgarbage},
   {"dofile", lua_internaldofile},
   {"dostring", lua_internaldostring},
   {"error", luaI_error},

+ 4 - 1
lua.h

@@ -2,7 +2,7 @@
 ** LUA - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
-** $Id: lua.h,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $
+** $Id: lua.h,v 4.3 1997/04/15 16:52:20 roberto Exp roberto $
 */
 
 
@@ -84,6 +84,9 @@ void	       lua_unref		(int ref);
 lua_Object     lua_createtable		(void);
 
 
+long	       lua_collectgarbage	(long limit);
+
+
 /* =============================================================== */
 /* some useful macros */
 

+ 7 - 6
table.c

@@ -3,7 +3,7 @@
 ** Module to control static tables
 */
 
-char *rcs_table="$Id: table.c,v 2.68 1997/04/07 14:48:53 roberto Exp roberto $";
+char *rcs_table="$Id: table.c,v 2.69 1997/05/14 18:38:29 roberto Exp roberto $";
 
 #include "luamem.h"
 #include "auxlib.h"
@@ -29,7 +29,7 @@ Word lua_nconstant = 0;
 static Long lua_maxconstant = 0;
 
 
-#define GARBAGE_BLOCK 50
+#define GARBAGE_BLOCK 100
 
 
 void luaI_initsymbol (void)
@@ -189,7 +189,7 @@ static void markall (void)
 }
 
 
-static void lua_collectgarbage (void)
+long lua_collectgarbage (long limit)
 {
   long recovered = 0;
   Hash *freetable;
@@ -199,21 +199,22 @@ static void lua_collectgarbage (void)
   freetable = luaI_hashcollector(&recovered);
   freestr = luaI_strcollector(&recovered);
   freefunc = luaI_funccollector(&recovered);
-  gc_block = 2*(gc_block-recovered);
   gc_nentity -= recovered;
+  gc_block = (limit == 0) ? 2*(gc_block-recovered) : gc_nentity+limit;
   luaI_hashcallIM(freetable);
   luaI_strcallIM(freestr);
   call_nilIM();
   luaI_hashfree(freetable);
   luaI_strfree(freestr);
   luaI_funcfree(freefunc);
+  return recovered;
 } 
 
 
 void lua_pack (void)
 {
-  if (gc_nentity++ >= gc_block)
-    lua_collectgarbage();
+  if (++gc_nentity >= gc_block)
+    lua_collectgarbage(0);
 }