diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-10-17 17:03:23 -0200 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-10-17 17:03:23 -0200 |
commit | f8c8159362f4bb8820908085adcb06900ef33b4c (patch) | |
tree | 2cbe498f152dad434973e4b718ba04dd08ca3b83 | |
parent | d1c5f4294365e9c5dbcd7f57bd0e3d55b548329c (diff) | |
download | lua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.gz lua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.bz2 lua-f8c8159362f4bb8820908085adcb06900ef33b4c.zip |
adaptative garbage collection.
-rw-r--r-- | hash.c | 7 | ||||
-rw-r--r-- | table.c | 13 | ||||
-rw-r--r-- | table.h | 3 |
3 files changed, 14 insertions, 9 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.7 1994/09/08 15:27:10 celes Exp celes $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.8 1994/10/11 12:59:49 celes Exp $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -52,7 +52,7 @@ static int redimension (int nhash) | |||
52 | return nhash*2+1; | 52 | return nhash*2+1; |
53 | } | 53 | } |
54 | 54 | ||
55 | static int index (Hash *t, Object *ref) /* hash function */ | 55 | static int hashindex (Hash *t, Object *ref) /* hash function */ |
56 | { | 56 | { |
57 | switch (tag(ref)) | 57 | switch (tag(ref)) |
58 | { | 58 | { |
@@ -97,7 +97,7 @@ static int equalObj (Object *t1, Object *t2) | |||
97 | 97 | ||
98 | static int present (Hash *t, Object *ref) | 98 | static int present (Hash *t, Object *ref) |
99 | { | 99 | { |
100 | int h = index(t, ref); | 100 | int h = hashindex(t, ref); |
101 | if (h < 0) return h; | 101 | if (h < 0) return h; |
102 | while (tag(ref(node(t, h))) != T_NIL) | 102 | while (tag(ref(node(t, h))) != T_NIL) |
103 | { | 103 | { |
@@ -195,6 +195,7 @@ void lua_hashcollector (void) | |||
195 | if (prev == NULL) listhead = next; | 195 | if (prev == NULL) listhead = next; |
196 | else prev->next = next; | 196 | else prev->next = next; |
197 | hashdelete(curr_array); | 197 | hashdelete(curr_array); |
198 | ++lua_recovered; | ||
198 | } | 199 | } |
199 | else | 200 | else |
200 | { | 201 | { |
@@ -3,7 +3,7 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; | 6 | char *rcs_table="$Id: table.c,v 2.3 1994/08/03 14:15:46 celes Exp $"; |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -39,6 +39,7 @@ int lua_nfile; | |||
39 | #define GARBAGE_BLOCK 256 | 39 | #define GARBAGE_BLOCK 256 |
40 | Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ | 40 | Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ |
41 | Word lua_nentity; /* counter of new entities (strings and arrays) */ | 41 | Word lua_nentity; /* counter of new entities (strings and arrays) */ |
42 | Word lua_recovered; /* counter of recovered entities (strings and arrays) */ | ||
42 | 43 | ||
43 | 44 | ||
44 | /* | 45 | /* |
@@ -210,10 +211,15 @@ void lua_pack (void) | |||
210 | /* mark symbol table strings */ | 211 | /* mark symbol table strings */ |
211 | lua_travsymbol(lua_markobject); | 212 | lua_travsymbol(lua_markobject); |
212 | 213 | ||
214 | lua_recovered=0; | ||
215 | |||
213 | lua_strcollector(); | 216 | lua_strcollector(); |
214 | lua_hashcollector(); | 217 | lua_hashcollector(); |
215 | 218 | ||
216 | lua_nentity = 0; /* reset counter */ | 219 | printf("lua_pack: lua_block=%d lua_recovered=%d %%=%.2f\n",lua_block,lua_recovered,100.0*lua_recovered/lua_block); |
220 | |||
221 | lua_nentity = 0; /* reset counter */ | ||
222 | lua_block=2*lua_block-3*lua_recovered/2; /* adapt block size */ | ||
217 | } | 223 | } |
218 | 224 | ||
219 | 225 | ||
@@ -224,9 +230,6 @@ char *lua_createstring (char *s) | |||
224 | { | 230 | { |
225 | if (s == NULL) return NULL; | 231 | if (s == NULL) return NULL; |
226 | 232 | ||
227 | if (lua_nentity == lua_block) | ||
228 | lua_pack (); | ||
229 | lua_nentity++; | ||
230 | return lua_strcreate(s); | 233 | return lua_strcreate(s); |
231 | } | 234 | } |
232 | 235 | ||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** Module to control static tables | 2 | ** Module to control static tables |
3 | ** TeCGraf - PUC-Rio | 3 | ** TeCGraf - PUC-Rio |
4 | ** $Id: table.h,v 2.1 1994/04/20 22:07:57 celes Exp celes $ | 4 | ** $Id: table.h,v 2.2 1994/07/19 21:27:18 celes Exp $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef table_h | 7 | #ifndef table_h |
@@ -15,6 +15,7 @@ extern int lua_nfile; | |||
15 | 15 | ||
16 | extern Word lua_block; | 16 | extern Word lua_block; |
17 | extern Word lua_nentity; | 17 | extern Word lua_nentity; |
18 | extern Word lua_recovered; | ||
18 | 19 | ||
19 | 20 | ||
20 | void lua_initconstant (void); | 21 | void lua_initconstant (void); |