lua-users home
lua-l archive

Re: Reducing memory consumption

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Nick Trout wrote:
>
> If I have a list of functions to register in C this amounts to something
> _like_:
> 
> // C
> Lua_function_info fns[] = {
> 	{ "ThisFunctionNameIsVeryDescriptive1", myFnCallback1 },
> 	{ "ThisFunctionNameIsVeryDescriptive2", myFnCallback2 },
> 	{ "ThisFunctionNameIsVeryDescriptive3", myFnCallback3 },
> 	{ "ThisFunctionNameIsVeryDescriptive4", myFnCallback4 },
> 	{ "ThisFunctionNameIsVeryDescriptiveN", myFnCallbackN },
> 	{ 0, 0 }
> };
> 
> lua_register_list(fns);
> 
> So we end up with duplicate copies of all those strings (because Lua
> copies the function name) and closures around the C functions (32 bytes
> each). I can't register these as local variables (so they're indexed) so
> I can't get the space back. (Perhaps I could somehow register them
> through the debug library?)
/* C side */
int
gimme_funcs(lua_State *L)
{
 lua_pushcfunction(L, myFnCallback1);
 lua_pushcfunction(L, myFnCallback2);
 lua_pushcfunction(L, myFnCallback3);
 lua_pushcfunction(L, myFnCallback4);
 lua_pushcfunction(L, myFnCallbackN);
 return 5;
}
 ...
 lua_register(L, "gimme_funcs", gimme_funcs);
 ...
-- lua side
local
 ThisFunctionNameIsVeryDescriptive1,
 ThisFunctionNameIsVeryDescriptive2,
 ThisFunctionNameIsVeryDescriptive3,
 ThisFunctionNameIsVeryDescriptive4,
 ThisFunctionNameIsVeryDescriptiveN = gimme_funcs()
But don't forget to strip debug infos...
Ciao, ET.

AltStyle によって変換されたページ (->オリジナル) /