lua-users home
lua-l archive

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


the core of concept.

in lua (and many others languages) string are imutable (like java too)

any change of value of variable you can rehash it (recycle)

in c you can usage char array (static or dynamic)
static: char buf[128]
dynamic: malloc/calloc





---- Em Qui, 26 mai 2022 09:18:55 -0300 Duke Normandin <dukeofpurl@gmx.com> escreveu ----

On Wed, 25 May 2022 19:42:12 +0000 (UTC)
Hector Vido <hector_vido@yahoo.com.br> wrote:

> ... But I think this is
> explained in that way because of string concatenations. If you do
> something like this inside a loop: myName = myName .. 'blah'
> This will leave a lot of "new strings" in memory to be cleaned by
> the garbage collector, instead of just "replace" the value of
> "myName" variable.

Thank you Hector for your explanation.
I tested it in the Lua REPL:
myName = 'hector'
myName = myName .. ' vido'
print(myName) => hector vido

So the char array "myName" has a new value. Correct?
and there is now an abandoned char array that contain only 'hector'?
which the gc will eventually destroy?

--
Duke
** Bottom posting text only is the netiquette way! **