Every time you create a new string you have to allocate memory. Equal strings share the same memory though. So...
Code:
-- Assume each block here is called independantly, not in order.
-- If they are called all at once, new strings would not be allocated.
local a, b, c = "a", "b", "c"
local abc = a..b..c
-- This allocates 4 different strings
local abc = "a".."b".."c"
-- This allocates one string
local abc = string.format("%s%s%s", "a", "b", "c")
-- This allocates 5 strings
local x = {}
local m = "m"
for i=1,10000 do
x[i] = "m"
end
-- This allocates 1 string... but also 10,000 table indexes which might take up a tiny chunk of memory
Smart use of concat (..) is your friend... as does smart use of string.format. Depending on what you're doing each has it's advantage in terms of memory consumption.
As for tostring(), why are you using it in the first place? This works just fine:
Code:
local x = 0
local s = "Blah"..x
The times when you must call tostring are little to none. I personally can't think of a single time I've had to use it.