[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Reducing memory consumption
- From: Mark Hamburg <mhamburg@...>
- Date: Fri, 27 Aug 2004 21:10:42 -0700
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