49
edits
| Line 55: | Line 55: | ||
Each function closure takes 20 bytes of RAM. The below code will use 20000 bytes: | Each function closure takes 20 bytes of RAM. The below code will use 20000 bytes: | ||
<pre> | <pre> | ||
for t=1,1000 | for t=1,1000 do | ||
x = function() end | x = function() end | ||
end | end | ||
| Line 62: | Line 62: | ||
<pre> | <pre> | ||
local semistatic = "hi!" | local semistatic = "hi!" | ||
for t=1,1000 | for t=1,1000 do | ||
x = function() print(semistatic) end | x = function() print(semistatic) end | ||
end | end | ||
| Line 68: | Line 68: | ||
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> | <pre> | ||
for t=1,1000 | for t=1,1000 do | ||
x = function() print(t) end | x = function() print(t) end | ||
end | end | ||
| Line 74: | Line 74: | ||
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> | <pre> | ||
for t=1,500 | for t=1,500 do | ||
for i=1,2 | for i=1,2 do | ||
x = function() print(t) end | x = function() print(t) end | ||
end | end | ||
end | end | ||
</pre> | </pre> | ||