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 /table.c | |
parent | d1c5f4294365e9c5dbcd7f57bd0e3d55b548329c (diff) | |
download | lua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.gz lua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.bz2 lua-f8c8159362f4bb8820908085adcb06900ef33b4c.zip |
adaptative garbage collection.
Diffstat (limited to 'table.c')
-rw-r--r-- | table.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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 | ||