lua-users home
lua-l archive

Re: Reducing memory consumption

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


Somewhat less successful at the immediate poof, but:
 local funcs = gimme_funcs() -- returns a table by name
 local func1 = funcs.func1
 local func2 = funcs.func2
 etc.
 func = nil
For a balance of speed v space, cache the results of gimme_funcs via a weak
table. In other words:
 local gimme_funcs_cache = setmetatable( {}, { __mode = "kv" } )
 function gimme_funcs()
 local funcs = gimme_funcs_cache[ 1 ]
 if not funcs then
 funcs = real_gimme_funcs()
 gimme_funcs_cache[ 1 ] = funcs
 end
 return funcs
 end
Mark

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