demoted headings
mNo edit summary |
(demoted headings) |
||
| Line 4: | Line 4: | ||
Some information on the memory usage of data in the WoW LUA environment (Expanding upon a forum posting). | Some information on the memory usage of data in the WoW LUA environment (Expanding upon a forum posting). | ||
= Data = | == Data == | ||
There are two basic classes of data that can be assigned to variables, passed around, etc, in LUA. | There are two basic classes of data that can be assigned to variables, passed around, etc, in LUA. | ||
== Values == | === Values === | ||
Simple data types like numbers and booleans are represented as their actual <b>values</b>, and are passed around as such. | Simple data types like numbers and booleans are represented as their actual <b>values</b>, and are passed around as such. | ||
== References == | === References === | ||
Complex data types (Userdata, Strings, and Tables) are represented as <b>references</b> to their actual value. Each reference fits in the same amount of memory as a value, but then the actual object that is referenced takes up additional space. | Complex data types (Userdata, Strings, and Tables) are represented as <b>references</b> to their actual value. Each reference fits in the same amount of memory as a value, but then the actual object that is referenced takes up additional space. | ||
=== Strings === | ==== Strings ==== | ||
The contents of strings are immutable, so once created a string cannot be changed, just replaced with another string. This allows LUA to maintain a pool of every distinct string value in use, such that multiple occurrences of the same string are all in fact references to the same unchangeable string object. | The contents of strings are immutable, so once created a string cannot be changed, just replaced with another string. This allows LUA to maintain a pool of every distinct string value in use, such that multiple occurrences of the same string are all in fact references to the same unchangeable string object. | ||
If you have a table containing 30,000 entries of "Visit http://www.wowwiki.com/ to find out how to get more out of the World of Warcraft", there's actually only one instance of the text itself. Each occurrence of the string is a reference to that shared instance. | If you have a table containing 30,000 entries of "Visit http://www.wowwiki.com/ to find out how to get more out of the World of Warcraft", there's actually only one instance of the text itself. Each occurrence of the string is a reference to that shared instance. | ||
=== Tables === | ==== Tables ==== | ||
Unlike strings, tables can be altered, and may grow as entries are added to them. A table is made up of 3 parts: | Unlike strings, tables can be altered, and may grow as entries are added to them. A table is made up of 3 parts: | ||
| Line 31: | Line 31: | ||
Tables which mix both forms of values (list entries, and map entries) use a mix of the two entry types | Tables which mix both forms of values (list entries, and map entries) use a mix of the two entry types | ||
= Local Variables = | == Local Variables == | ||
Locally scoped variables in functions are stored on the stack, rather than being part of the garbage collected memory heap, however if the variable contains a reference type, then the actual data referenced is not on the stack. (Though it's not actually a stack, per se, see the LUA source code for details) | Locally scoped variables in functions are stored on the stack, rather than being part of the garbage collected memory heap, however if the variable contains a reference type, then the actual data referenced is not on the stack. (Though it's not actually a stack, per se, see the LUA source code for details) | ||