lua-users home
lua-l archive

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

I'm working on a new (yet another...) programming language, and I'm
about to start working on the string system. I'm looking with interest
at Lua's string handling, as it works very well.

I'm already sold on having immutable strings, as there are lots of
advantages with regard to sharing of string data etc, but what are the
advantages to having atomised strings (i.e., each string has one and
precisely one copy in memory)? Is it to allow strings to be compared for
equality by just comparing their pointers? My language isn't based
around key/value pairs the way Lua is, so that may not be as important
to me; are there any other benefits?

Also, what's the performance characteristics of using atomised strings?
In particular, I'm wondering what the amortised performance of adding a
new string to the system is like; when using atomised strings you need
to do a lookup of the string table to see if the string is there, plus
an optional memory allocation if it turns out that it's not. A
non-atomised implementation doesn't do the lookup but has to always do
the memory allocation.

What hash function does Lua use for strings?

┌─── ───── ─────
│ "Thou who might be our Father, who perhaps may be in Heaven, hallowed
│ be Thy Name, if Name Thou hast and any desire to see it hallowed..."
│ --- _Creatures of Light and Darkness_, Roger Zelazny

Attachment: signature.asc
Description: OpenPGP digital signature