lua-users home
lua-l archive

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


On Mon, Aug 25, 2014 at 3:45 PM, Robert Virding <rvirding@gmail.com> wrote:

> 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?

Typically people don't leave around a lot of references to unique data
they don't plan to process again later -- I imagine the GC saves them,
yes :>

> 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.

I am not sure why creating many unique atoms crashes the system but
using binary/strings would not.  Surely deduplicated atoms would avoid
out-of-memory situations better than duplicated binary/strings.

What I'm talking about here is I know the buffer I recv() into will
usually be unique, mutates often, and has a short lifespan -- it would
seem appropriate for the buffer to be mutable (represented as
userdata).  What I've been talking about is trying to trick Lua into
thinking userdata is really a string, and accessing it safely (looking
at the data portion of userdata (which doesn't start in the same place
as the data portion of a Lua string)).