Add custom API to prevent Lua Objects from being garbage collected.
This is intended to for Ardour LuaBridge bindings (~1MB Objects:
tables, functions and userdata).
The bindings are persistent and the gc can skip them in mark & sweep
phases. This is a significant performance improvement for garbage
collection.
Note. The next version of Lua (5.4) will come with a generational-gc
rather than an incremental, so extending the API at this point in time
is acceptable.
GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
o->marked = luaC_white(g);
o->tt = tt;
- o->next = g->allgc;
- g->allgc = o;
+ if (g->gcmlock) {
+ white2gray(o); /* gray forever */
+ o->next = g->fixedgc;
+ g->fixedgc = o;
+ } else {
+ o->next = g->allgc;
+ g->allgc = o;
+ }
return o;
}
/* }====================================================== */
-
+LUA_API void lua_mlock (lua_State *L, int en) {
+ global_State *g = G(L);
+ g->gcmlock = en;
+}
g->gcfinnum = 0;
g->gcpause = LUAI_GCPAUSE;
g->gcstepmul = LUAI_GCMUL;
+ g->gcmlock = 0;
for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
/* memory allocation error: free partial state */
unsigned int gcfinnum; /* number of finalizers to call in each GC step */
int gcpause; /* size of pause between successive GCs */
int gcstepmul; /* GC 'granularity' */
+ int gcmlock; /* memory lock new objects - fixedgc */
lua_CFunction panic; /* to be called in unprotected errors */
struct lua_State *mainthread;
const lua_Number *version; /* pointer to version number */
LUA_API int (lua_gc) (lua_State *L, int what, int data);
+LUA_API void (lua_mlock) (lua_State *L, int enable);
+
/*
** miscellaneous functions