aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 10:55:41 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-12-28 10:55:41 -0200
commit0183b8030c80f57b87874ff7867ccdb172d9d3dc (patch)
tree1033b5a84489a2f1f1bd210b1b120155cd7aeed7 /lgc.c
parent8c49e198654567f770a7d5081b886a7c35201d81 (diff)
downloadlua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.gz
lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.tar.bz2
lua-0183b8030c80f57b87874ff7867ccdb172d9d3dc.zip
`free' gets size of the block: complete control over memory use
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/lgc.c b/lgc.c
index 7b35ee03..8c63570a 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.73 2000/11/24 17:39:56 roberto Exp roberto $ 2** $Id: lgc.c,v 1.74 2000/12/26 18:46:09 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -37,11 +37,11 @@ static void protomark (Proto *f) {
37 int i; 37 int i;
38 f->marked = 1; 38 f->marked = 1;
39 strmark(f->source); 39 strmark(f->source);
40 for (i=0; i<f->nkstr; i++) 40 for (i=0; i<f->sizekstr; i++)
41 strmark(f->kstr[i]); 41 strmark(f->kstr[i]);
42 for (i=0; i<f->nkproto; i++) 42 for (i=0; i<f->sizekproto; i++)
43 protomark(f->kproto[i]); 43 protomark(f->kproto[i]);
44 for (i=0; i<f->nlocvars; i++) /* mark local-variable names */ 44 for (i=0; i<f->sizelocvars; i++) /* mark local-variable names */
45 strmark(f->locvars[i].varname); 45 strmark(f->locvars[i].varname);
46 } 46 }
47} 47}
@@ -248,8 +248,7 @@ static void collectstrings (lua_State *L, int all) {
248 else { /* collect */ 248 else { /* collect */
249 *p = next->nexthash; 249 *p = next->nexthash;
250 L->strt.nuse--; 250 L->strt.nuse--;
251 L->nblocks -= sizestring(next->len); 251 luaM_free(L, next, sizestring(next->len));
252 luaM_free(L, next);
253 } 252 }
254 } 253 }
255 } 254 }
@@ -273,7 +272,6 @@ static void collectudata (lua_State *L, int all) {
273 *p = next->nexthash; 272 *p = next->nexthash;
274 next->nexthash = L->TMtable[tag].collected; /* chain udata */ 273 next->nexthash = L->TMtable[tag].collected; /* chain udata */
275 L->TMtable[tag].collected = next; 274 L->TMtable[tag].collected = next;
276 L->nblocks -= sizestring(next->len);
277 L->udt.nuse--; 275 L->udt.nuse--;
278 } 276 }
279 } 277 }
@@ -286,9 +284,8 @@ static void collectudata (lua_State *L, int all) {
286static void checkMbuffer (lua_State *L) { 284static void checkMbuffer (lua_State *L) {
287 if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ 285 if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */
288 size_t newsize = L->Mbuffsize/2; /* still larger than MINBUFFER */ 286 size_t newsize = L->Mbuffsize/2; /* still larger than MINBUFFER */
289 L->nblocks -= (L->Mbuffsize - newsize)*sizeof(char); 287 luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, newsize, char);
290 L->Mbuffsize = newsize; 288 L->Mbuffsize = newsize;
291 luaM_reallocvector(L, L->Mbuffer, newsize, char);
292 } 289 }
293} 290}
294 291
@@ -320,7 +317,7 @@ static void callgcTMudata (lua_State *L) {
320 L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ 317 L->TMtable[tag].collected = udata->nexthash; /* remove it from list */
321 tsvalue(&o) = udata; 318 tsvalue(&o) = udata;
322 callgcTM(L, &o); 319 callgcTM(L, &o);
323 luaM_free(L, udata); 320 luaM_free(L, udata, sizeudata(udata->len));
324 } 321 }
325 } 322 }
326} 323}