lua-users home
lua-l archive

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



> Maybe I'm not thinking in Lua clearly here. I'm not in love 
> with objects: I just want to say, here's a prototype of a 
> structure. Clone it, change a few things, make it work as you want.


Lua hashes strings and doesn't store duplicates:

> = gcinfo()  -- return Lua memory usage and gc threshold
17      29
> a = string.rep('z', 100000)
> = gcinfo()
163     326
> b = string.rep('z', 100000)
> = gcinfo()
163     326
> b = string.rep('a', 100000)
> = gcinfo()
261     522

Both variables reference the same string object as long as the strings
they are supposed to represent are the same value. If you assign a new
value to a variable it will not change both values.

Code is here:
http://www.lua.org/source/5.0/src_lstring.c.html


/Nick