Customize Lua GC, add object-memory-lock API.

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.
This commit is contained in:
Robin Gareus 2018-03-19 01:33:13 +01:00
parent 2092934721
commit f2ca0c144b
4 changed files with 16 additions and 3 deletions

View file

@ -328,6 +328,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
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 */