buffer can shrink when too big

This commit is contained in:
Roberto Ierusalimschy 1999-11-10 13:40:46 -02:00
parent d915cf4f9d
commit 0c725b2492
2 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbuffer.c,v 1.8 1999/02/25 19:20:40 roberto Exp roberto $ ** $Id: lbuffer.c,v 1.9 1999/02/26 15:48:55 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -24,9 +24,8 @@
static void Openspace (int size) { static void Openspace (int size) {
lua_State *l = L; /* to optimize */ lua_State *l = L; /* to optimize */
size += EXTRABUFF; l->Mbuffsize = (l->Mbuffnext+size+EXTRABUFF)*2;
l->Mbuffsize = l->Mbuffnext+size; luaM_reallocvector(l->Mbuffer, l->Mbuffsize, char);
luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
} }

12
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.29 1999/10/14 19:13:31 roberto Exp roberto $ ** $Id: lgc.c,v 1.30 1999/11/04 17:22:26 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -8,6 +8,7 @@
#include "ldo.h" #include "ldo.h"
#include "lfunc.h" #include "lfunc.h"
#include "lgc.h" #include "lgc.h"
#include "lmem.h"
#include "lobject.h" #include "lobject.h"
#include "lref.h" #include "lref.h"
#include "lstate.h" #include "lstate.h"
@ -83,9 +84,10 @@ static void travstack (void) {
static void travlock (void) { static void travlock (void) {
int i; int i;
for (i=0; i<L->refSize; i++) for (i=0; i<L->refSize; i++) {
if (L->refArray[i].status == LOCK) if (L->refArray[i].st == LOCK)
markobject(&L->refArray[i].o); markobject(&L->refArray[i].o);
}
} }
@ -254,6 +256,10 @@ long lua_collectgarbage (long limit) {
luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
recovered = recovered - L->nblocks; recovered = recovered - L->nblocks;
L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit;
if (L->Mbuffsize > L->Mbuffnext*4) { /* is buffer too big? */
L->Mbuffsize /= 2; /* still larger than Mbuffnext*2 */
luaM_reallocvector(L->Mbuffer, L->Mbuffsize, char);
}
return recovered; return recovered;
} }