lua-users home
lua-l archive

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


OK, this is what I understood by pooling.

What I was wondering is that if you have a system where each new string is interned then the string table will keep growing with new strings. This does make for very fast checking of string equality. However, if you have dynamically created strings, for example data coming into the system from the outside, then the string table will grow and eventually crash the system.

While I definitely agree that strings should be immutable, immutable data is good, this means that working with strings will dynamically create new strings all the time which will exacerbate the problem. Or are they removed by the garbage collector?

We have the same problem in Erlang with atoms which are interned and dynamically creating atoms in an uncontrolled way will eventually crash the system. The solution there is to avoid dynamically creating atom but use binaries/string instead which are not interned.

This is why I was wondering how Lua attacked this problem.

Robert



On 26 August 2014 00:19, Coroutines <coroutines@gmail.com> wrote:
On Mon, Aug 25, 2014 at 3:07 PM, Robert Virding <rvirding@gmail.com> wrote:
> Got into this discussion late.
>
> If you have pooling of strings how can you safely use them for dynamic data,
> for example from input, if you want the system to survive for any length of
> time? Or have I misunderstood what is meant by pooling?

Hmm, please elaborate :>  We've been talking about pooled strings in
the sense that once a string is created -- it does not change.  Not
only that, but it is checked for equality against the existing strings
Lua has already "seen"/interned.  When a string is created a hash is
computed based on the contents of that string.  So when you compare
'cat' == 'dog' Lua is internally doing a comparison of the hash of
"cat" to the hash of "dog" -- but it also may be as simple as a
pointer comparison.  (I don't know for sure in every instance)