diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-10 13:40:46 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-10 13:40:46 -0200 |
commit | 0c725b2492051bdb776af3dae31881a162000894 (patch) | |
tree | d24b9106614f9c54a6ea75a57acdd0ab58964b5c | |
parent | d915cf4f9dbe525f8faeb4cb04df13d5f08692da (diff) | |
download | lua-0c725b2492051bdb776af3dae31881a162000894.tar.gz lua-0c725b2492051bdb776af3dae31881a162000894.tar.bz2 lua-0c725b2492051bdb776af3dae31881a162000894.zip |
buffer can shrink when too big
-rw-r--r-- | lbuffer.c | 7 | ||||
-rw-r--r-- | lgc.c | 12 |
2 files changed, 12 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuffer.c,v 1.8 1999/02/25 19:20:40 roberto Exp roberto $ | 2 | ** $Id: lbuffer.c,v 1.9 1999/02/26 15:48:55 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -24,9 +24,8 @@ | |||
24 | 24 | ||
25 | static void Openspace (int size) { | 25 | static void Openspace (int size) { |
26 | lua_State *l = L; /* to optimize */ | 26 | lua_State *l = L; /* to optimize */ |
27 | size += EXTRABUFF; | 27 | l->Mbuffsize = (l->Mbuffnext+size+EXTRABUFF)*2; |
28 | l->Mbuffsize = l->Mbuffnext+size; | 28 | luaM_reallocvector(l->Mbuffer, l->Mbuffsize, char); |
29 | luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT); | ||
30 | } | 29 | } |
31 | 30 | ||
32 | 31 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.29 1999/10/14 19:13:31 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.30 1999/11/04 17:22:26 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 | */ |
@@ -8,6 +8,7 @@ | |||
8 | #include "ldo.h" | 8 | #include "ldo.h" |
9 | #include "lfunc.h" | 9 | #include "lfunc.h" |
10 | #include "lgc.h" | 10 | #include "lgc.h" |
11 | #include "lmem.h" | ||
11 | #include "lobject.h" | 12 | #include "lobject.h" |
12 | #include "lref.h" | 13 | #include "lref.h" |
13 | #include "lstate.h" | 14 | #include "lstate.h" |
@@ -83,9 +84,10 @@ static void travstack (void) { | |||
83 | 84 | ||
84 | static void travlock (void) { | 85 | static void travlock (void) { |
85 | int i; | 86 | int i; |
86 | for (i=0; i<L->refSize; i++) | 87 | for (i=0; i<L->refSize; i++) { |
87 | if (L->refArray[i].status == LOCK) | 88 | if (L->refArray[i].st == LOCK) |
88 | markobject(&L->refArray[i].o); | 89 | markobject(&L->refArray[i].o); |
90 | } | ||
89 | } | 91 | } |
90 | 92 | ||
91 | 93 | ||
@@ -254,6 +256,10 @@ long lua_collectgarbage (long limit) { | |||
254 | luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ | 256 | luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ |
255 | recovered = recovered - L->nblocks; | 257 | recovered = recovered - L->nblocks; |
256 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; | 258 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; |
259 | if (L->Mbuffsize > L->Mbuffnext*4) { /* is buffer too big? */ | ||
260 | L->Mbuffsize /= 2; /* still larger than Mbuffnext*2 */ | ||
261 | luaM_reallocvector(L->Mbuffer, L->Mbuffsize, char); | ||
262 | } | ||
257 | return recovered; | 263 | return recovered; |
258 | } | 264 | } |
259 | 265 | ||