→Strings: make note of global hash table affecting measurements
(New page: Lua contains a fairly small set of data structures. This page aims to document how much size each structure uses, to aid addon programmers with memory optomization. This data is from WoW...) |
(→Strings: make note of global hash table affecting measurements) |
||
| Line 4: | Line 4: | ||
== Strings == | == Strings == | ||
Strings are allocated and garbage collected by the lua engine. Equal strings will not take up extra space (all strings are stored by reference). When a new string is allocated in memory, it will consume ( | Strings are allocated and garbage collected by the lua engine. Equal strings will not take up extra space (all strings are stored by reference). When a new string is allocated in memory, it will consume AT LEAST (17 + string length) bytes. However, strings are also tracked in a global hash table, which will grow as necessary, making the average memory consumption somewhere around 24+length bytes when the number of globally tracked strings grows. | ||
== Tables == | == Tables == | ||
| Line 47: | Line 47: | ||
t.reset = nil | t.reset = nil | ||
:''It should be noted that erasing a table is generally more expensive than collecting the table during GC. One may wish to simply allocate a new empty table.'' | :''It should be noted that erasing a table is generally more expensive than collecting the table during GC. One may wish to simply allocate a new empty table.'' | ||
== Function closures == | |||
Each function closure takes 20 bytes of RAM. The below code will use 20000 bytes: | |||
for t=1,1000 | |||
x = function() end | |||
end | |||
Each upvalue uses an additional 36 bytes of RAM for integers/booleans/refs. The below code will use 20000 + 36000 = 56000 bytes: | |||
for t=1,1000 | |||
x = function() print(t) end | |||
end | |||
[[Category:UI Technical Details]] | |||