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
** See Copyright Notice in lua.h
*/
@ -24,9 +24,8 @@
static void Openspace (int size) {
lua_State *l = L; /* to optimize */
size += EXTRABUFF;
l->Mbuffsize = l->Mbuffnext+size;
luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char, arrEM, MAX_INT);
l->Mbuffsize = (l->Mbuffnext+size+EXTRABUFF)*2;
luaM_reallocvector(l->Mbuffer, l->Mbuffsize, char);
}

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
** See Copyright Notice in lua.h
*/
@ -8,6 +8,7 @@
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lref.h"
#include "lstate.h"
@ -83,9 +84,10 @@ static void travstack (void) {
static void travlock (void) {
int i;
for (i=0; i<L->refSize; i++)
if (L->refArray[i].status == LOCK)
for (i=0; i<L->refSize; i++) {
if (L->refArray[i].st == LOCK)
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) */
recovered = recovered - L->nblocks;
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;
}