mirror of
https://github.com/lua/lua
synced 2025-03-24 06:32:51 +03:00
a different option for the GC
This commit is contained in:
parent
a56d889f72
commit
c6254dceff
8
lapi.c
8
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 2.21 2004/12/03 20:50:25 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -867,9 +867,9 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
|
||||
luaC_step(L);
|
||||
break;
|
||||
}
|
||||
case LUA_GCSETSTEPMUL: {
|
||||
res = g->stepmul;
|
||||
g->stepmul = data;
|
||||
case LUA_GCSETPACE: {
|
||||
res = g->gcpace;
|
||||
g->gcpace = data;
|
||||
break;
|
||||
}
|
||||
case LUA_GCSETINCMODE: {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.162 2004/12/07 18:31:34 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -182,9 +182,9 @@ static int luaB_gcinfo (lua_State *L) {
|
||||
|
||||
static int luaB_collectgarbage (lua_State *L) {
|
||||
static const char *const opts[] = {"stop", "restart", "collect",
|
||||
"count", "step", "setstepmul", "setincmode", NULL};
|
||||
"count", "step", "setpace", "setincmode", NULL};
|
||||
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
|
||||
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE};
|
||||
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETINCMODE};
|
||||
int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
|
||||
int ex = luaL_optint(L, 2, 0);
|
||||
luaL_argcheck(L, o >= 0, 1, "invalid option");
|
||||
|
10
lgc.c
10
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -27,6 +27,7 @@
|
||||
#define GCSWEEPMAX 10
|
||||
#define GCSWEEPCOST 30
|
||||
#define GCFINALIZECOST 100
|
||||
#define GCSTEPMUL 8
|
||||
|
||||
|
||||
#define FIXEDMASK bitmask(FIXEDBIT)
|
||||
@ -621,18 +622,17 @@ static l_mem singlestep (lua_State *L) {
|
||||
|
||||
void luaC_step (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul;
|
||||
l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * GCSTEPMUL;
|
||||
do {
|
||||
lim -= singlestep(L);
|
||||
if (g->gcstate == GCSpause)
|
||||
break;
|
||||
} while (lim > 0 || !g->incgc);
|
||||
if (g->incgc)
|
||||
if (g->gcstate != GCSpause)
|
||||
g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */
|
||||
else {
|
||||
lua_assert(g->totalbytes >= g->estimate);
|
||||
lua_assert(g->gcstate == GCSpause);
|
||||
g->GCthreshold = 2*g->estimate;
|
||||
g->GCthreshold = g->estimate + ((g->estimate/GCDIV) * g->gcpace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: llimits.h,v 1.60 2004/09/10 17:30:46 roberto Exp roberto $
|
||||
** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp roberto $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -73,6 +73,8 @@ typedef LUA_UACNUMBER l_uacNumber;
|
||||
typedef lu_int32 Instruction;
|
||||
|
||||
|
||||
/* divisor for GC pace */
|
||||
#define GCDIV 8
|
||||
|
||||
/* maximum stack for a Lua function */
|
||||
#define MAXSTACK 250
|
||||
|
4
lstate.c
4
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -193,7 +193,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
setnilvalue(gval(g->dummynode));
|
||||
gnext(g->dummynode) = NULL;
|
||||
g->totalbytes = sizeof(LG);
|
||||
g->stepmul = STEPMUL;
|
||||
g->gcpace = GCDIV;
|
||||
g->incgc = 1;
|
||||
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
|
||||
/* memory allocation error: free partial state */
|
||||
|
4
lstate.h
4
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 2.8 2004/09/15 20:39:42 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -85,7 +85,7 @@ typedef struct global_State {
|
||||
lu_mem totalbytes; /* number of bytes currently allocated */
|
||||
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
||||
lu_mem prevestimate; /* previous estimate */
|
||||
int stepmul; /* relative `speed' of the GC */
|
||||
int gcpace; /* relative `speed' of the GC */
|
||||
int incgc; /* 0 if GC is done non-incrementally */
|
||||
lua_CFunction panic; /* to be called in unprotected errors */
|
||||
TValue _registry;
|
||||
|
4
lua.h
4
lua.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.h,v 1.195 2004/12/01 15:50:18 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp roberto $
|
||||
** Lua - An Extensible Extension Language
|
||||
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
|
||||
** http://www.lua.org mailto:info@lua.org
|
||||
@ -225,7 +225,7 @@ LUA_API int lua_threadstatus (lua_State *L);
|
||||
#define LUA_GCCOLLECT 2
|
||||
#define LUA_GCCOUNT 3
|
||||
#define LUA_GCSTEP 4
|
||||
#define LUA_GCSETSTEPMUL 5
|
||||
#define LUA_GCSETPACE 5
|
||||
#define LUA_GCSETINCMODE 6
|
||||
|
||||
LUA_API int lua_gc (lua_State *L, int what, int data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user