lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 02/01/2014 9.57, Thijs Schreijer wrote:
local first  = [[ some 100mb stuff here ]]
> local second = first
> local third  = first .. "x"

You have two strings here: 'first' and 'second' are the same string, 'third' is a different string.

Assignment does not duplicate strings. Moreover, because strings are interned, there is a single copy of strings with equal contents; if you produce another identical string by different means (e.g. by concatenation), after the interning operation a single copy of the string will exist (please correct me if I am wrong here).

".." is a dangerous operator when doing many concatenations or when operating on large strings. table.concat and/or the C-level luaL_Buffer can be useful to reduce memory usage in these cases.

--
  Enrico