new way to count `nblocks' for GC (try to count bytes).
This commit is contained in:
36
lfunc.c
36
lfunc.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 1.29 2000/08/09 19:16:57 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 1.30 2000/08/22 17:44:17 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -13,19 +13,18 @@
|
||||
#include "lmem.h"
|
||||
#include "lstate.h"
|
||||
|
||||
#define gcsizeproto(L, p) numblocks(L, 0, sizeof(Proto))
|
||||
#define gcsizeclosure(L, c) numblocks(L, c->nupvalues, sizeof(Closure))
|
||||
|
||||
#define sizeclosure(n) (sizeof(Closure) + (lint32)sizeof(TObject)*((n)-1))
|
||||
|
||||
|
||||
Closure *luaF_newclosure (lua_State *L, int nelems) {
|
||||
Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure) +
|
||||
(lint32)sizeof(TObject)*(nelems-1));
|
||||
lint32 size = sizeclosure(nelems);
|
||||
Closure *c = (Closure *)luaM_malloc(L, size);
|
||||
c->next = L->rootcl;
|
||||
L->rootcl = c;
|
||||
c->mark = c;
|
||||
c->nupvalues = nelems;
|
||||
L->nblocks += gcsizeclosure(L, c);
|
||||
L->nblocks += size;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -33,7 +32,9 @@ Closure *luaF_newclosure (lua_State *L, int nelems) {
|
||||
Proto *luaF_newproto (lua_State *L) {
|
||||
Proto *f = luaM_new(L, Proto);
|
||||
f->code = NULL;
|
||||
f->ncode = 0;
|
||||
f->lineinfo = NULL;
|
||||
f->nlineinfo = 0;
|
||||
f->lineDefined = 0;
|
||||
f->source = NULL;
|
||||
f->kstr = NULL;
|
||||
@@ -47,13 +48,30 @@ Proto *luaF_newproto (lua_State *L) {
|
||||
f->next = L->rootproto;
|
||||
L->rootproto = f;
|
||||
f->marked = 0;
|
||||
L->nblocks += gcsizeproto(L, f);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
static size_t protosize (Proto *f) {
|
||||
return sizeof(Proto)
|
||||
+ f->nknum*sizeof(Number)
|
||||
+ f->nkstr*sizeof(TString *)
|
||||
+ f->nkproto*sizeof(Proto *)
|
||||
+ f->ncode*sizeof(Instruction)
|
||||
+ f->nlocvars*sizeof(struct LocVar)
|
||||
+ f->nlineinfo*sizeof(int);
|
||||
}
|
||||
|
||||
|
||||
void luaF_protook (lua_State *L, Proto *f, int pc) {
|
||||
f->ncode = pc; /* signal that proto was properly created */
|
||||
L->nblocks += protosize(f);
|
||||
}
|
||||
|
||||
|
||||
void luaF_freeproto (lua_State *L, Proto *f) {
|
||||
L->nblocks -= gcsizeproto(L, f);
|
||||
if (f->ncode > 0) /* function was properly created? */
|
||||
L->nblocks -= protosize(f);
|
||||
luaM_free(L, f->code);
|
||||
luaM_free(L, f->locvars);
|
||||
luaM_free(L, f->kstr);
|
||||
@@ -65,7 +83,7 @@ void luaF_freeproto (lua_State *L, Proto *f) {
|
||||
|
||||
|
||||
void luaF_freeclosure (lua_State *L, Closure *c) {
|
||||
L->nblocks -= gcsizeclosure(L, c);
|
||||
L->nblocks -= sizeclosure(c->nupvalues);
|
||||
luaM_free(L, c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user