lua-users home
lua-l archive

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


> Is this true for all six basic types of objects?
>
> Lua use automatic memory management for all types of objects e.g.
> strings. This means that you do not have to worry about allocation and
> deallocation of memory; Lua handles this for you. A string may contain
> a single letter or a whole book. Lua handles large objects quite
> efficiently. Programs that manipulate strings with 100K or even 1M
> characters are not unusual in Lua.
>
> Then I don't understand: You cannot change a character inside a string,
> as in C; instead, you create a new string with the desired
> modifications.
>
> If I would like to change or append a few bytes in or to an 1M string,
> Lua creates a new 1M string?
>
> Markus

Lua's internal system is heavily dependent on strings being represented by
hash values.  If a string stored in a table were to change by one character,
it's hash value would then change, and it would no longer be in the correct
position of the table (a search for the string wouldn't be able to find it).

It's much simpler just to have immutable strings.  But if you need string
buffers, you can implement them with lua's extension mechanisms without too
much trouble.

Ben