adaptative garbage collection.

This commit is contained in:
Waldemar Celes 1994-10-17 17:03:23 -02:00
parent d1c5f42943
commit f8c8159362
3 changed files with 14 additions and 9 deletions

7
hash.c
View File

@ -3,7 +3,7 @@
** hash manager for lua ** hash manager for lua
*/ */
char *rcs_hash="$Id: hash.c,v 2.7 1994/09/08 15:27:10 celes Exp celes $"; char *rcs_hash="$Id: hash.c,v 2.8 1994/10/11 12:59:49 celes Exp $";
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -52,7 +52,7 @@ static int redimension (int nhash)
return nhash*2+1; return nhash*2+1;
} }
static int index (Hash *t, Object *ref) /* hash function */ static int hashindex (Hash *t, Object *ref) /* hash function */
{ {
switch (tag(ref)) switch (tag(ref))
{ {
@ -97,7 +97,7 @@ static int equalObj (Object *t1, Object *t2)
static int present (Hash *t, Object *ref) static int present (Hash *t, Object *ref)
{ {
int h = index(t, ref); int h = hashindex(t, ref);
if (h < 0) return h; if (h < 0) return h;
while (tag(ref(node(t, h))) != T_NIL) while (tag(ref(node(t, h))) != T_NIL)
{ {
@ -195,6 +195,7 @@ void lua_hashcollector (void)
if (prev == NULL) listhead = next; if (prev == NULL) listhead = next;
else prev->next = next; else prev->next = next;
hashdelete(curr_array); hashdelete(curr_array);
++lua_recovered;
} }
else else
{ {

11
table.c
View File

@ -3,7 +3,7 @@
** Module to control static tables ** Module to control static tables
*/ */
char *rcs_table="$Id: table.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; char *rcs_table="$Id: table.c,v 2.3 1994/08/03 14:15:46 celes Exp $";
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -39,6 +39,7 @@ int lua_nfile;
#define GARBAGE_BLOCK 256 #define GARBAGE_BLOCK 256
Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */
Word lua_nentity; /* counter of new entities (strings and arrays) */ Word lua_nentity; /* counter of new entities (strings and arrays) */
Word lua_recovered; /* counter of recovered entities (strings and arrays) */
/* /*
@ -210,10 +211,15 @@ void lua_pack (void)
/* mark symbol table strings */ /* mark symbol table strings */
lua_travsymbol(lua_markobject); lua_travsymbol(lua_markobject);
lua_recovered=0;
lua_strcollector(); lua_strcollector();
lua_hashcollector(); lua_hashcollector();
printf("lua_pack: lua_block=%d lua_recovered=%d %%=%.2f\n",lua_block,lua_recovered,100.0*lua_recovered/lua_block);
lua_nentity = 0; /* reset counter */ lua_nentity = 0; /* reset counter */
lua_block=2*lua_block-3*lua_recovered/2; /* adapt block size */
} }
@ -224,9 +230,6 @@ char *lua_createstring (char *s)
{ {
if (s == NULL) return NULL; if (s == NULL) return NULL;
if (lua_nentity == lua_block)
lua_pack ();
lua_nentity++;
return lua_strcreate(s); return lua_strcreate(s);
} }

View File

@ -1,7 +1,7 @@
/* /*
** Module to control static tables ** Module to control static tables
** TeCGraf - PUC-Rio ** TeCGraf - PUC-Rio
** $Id: table.h,v 2.1 1994/04/20 22:07:57 celes Exp celes $ ** $Id: table.h,v 2.2 1994/07/19 21:27:18 celes Exp $
*/ */
#ifndef table_h #ifndef table_h
@ -15,6 +15,7 @@ extern int lua_nfile;
extern Word lua_block; extern Word lua_block;
extern Word lua_nentity; extern Word lua_nentity;
extern Word lua_recovered;
void lua_initconstant (void); void lua_initconstant (void);