49
edits
| Line 60: | Line 60: | ||
</pre> | </pre> | ||
Upvalues that do not change only uses 4 bytes per closure. The below code will use 20000 + 4000 = 24000 bytes: | Upvalues that do not change only uses 4 bytes per closure. The below code will use 20000 + 4000 = 24000 bytes: | ||
<pre> | |||
local semistatic = "hi!" | local semistatic = "hi!" | ||
for t=1,1000 | for t=1,1000 | ||
x = function() print(semistatic) end | x = function() print(semistatic) end | ||
end | end | ||
</pre> | |||
However, upvalues that actually ''change'' use an additional 32 bytes. The below code will use 20000 + 4000 + 32000 = 56000 bytes: | However, upvalues that actually ''change'' use an additional 32 bytes. The below code will use 20000 + 4000 + 32000 = 56000 bytes: | ||
<pre> | |||
for t=1,1000 | |||
x = function() print(t) end | x = function() print(t) end | ||
end | end | ||
</pre> | |||
And finally, a mix: The below code will use 20*2*500 + 4*2*500 + 32*500 = 40000 bytes | And finally, a mix: The below code will use 20*2*500 + 4*2*500 + 32*500 = 40000 bytes | ||
<pre> | |||
for t=1,'''500''' | for t=1,'''500''' | ||
for i=1,2 | for i=1,2 | ||
| Line 76: | Line 79: | ||
end | end | ||
end | end | ||
</pre> | |||