From 907368ead5978b689a97118b75e89a2095122530 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 23 Oct 1997 14:26:37 -0200 Subject: GC now considers an "estimate" of object size, instead of just the number of objects. --- lstring.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lstring.c') diff --git a/lstring.c b/lstring.c index 1b82cf20..cc67c66d 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ +** $Id: lstring.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -16,6 +16,9 @@ #define NUM_HASHS 61 +#define gcsizestring(l) (1+(l/64)) + + GCnode luaS_root = {NULL, 0}; /* list of global variables */ @@ -89,16 +92,19 @@ static TaggedString *newone(char *buff, int tag, unsigned long h) { TaggedString *ts; if (tag == LUA_T_STRING) { - ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+strlen(buff)); + long l = strlen(buff); + ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); strcpy(ts->str, buff); ts->u.globalval.ttype = LUA_T_NIL; /* initialize global value */ ts->constindex = 0; + luaO_nblocks += gcsizestring(l); } else { ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)); ts->u.d.v = buff; ts->u.d.tag = tag == LUA_ANYTAG ? 0 : tag; ts->constindex = -1; /* tag -> this is a userdata */ + luaO_nblocks++; } ts->head.marked = 0; ts->head.next = (GCnode *)ts; /* signal it is in no list */ @@ -126,7 +132,6 @@ static TaggedString *insert (char *buff, int tag, stringtable *tb) i = (i+1)%tb->size; } /* not found */ - ++luaO_nentities; if (j != -1) /* is there an EMPTY space? */ i = j; else @@ -158,6 +163,7 @@ void luaS_free (TaggedString *l) { while (l) { TaggedString *next = (TaggedString *)l->head.next; + luaO_nblocks -= (l->constindex == -1) ? 1 : gcsizestring(strlen(l->str)); luaM_free(l); l = next; } @@ -196,7 +202,6 @@ TaggedString *luaS_collector (void) t->head.next = (GCnode *)frees; frees = t; tb->hash[j] = ∅ - --luaO_nentities; } } } -- cgit v1.2.3-55-g6feb