[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Pooling of strings is good
- From: Coroutines <coroutines@...>
- Date: Fri, 22 Aug 2014 04:13:30 -0700
On Fri, Aug 22, 2014 at 3:59 AM, Jay Carlson <nop@nop.com> wrote:
> Mutable strings are...a folly of a quaint, bygone era. They are warts on
> otherwise timeless designs like Scheme and Smalltalk.
>
> Get a mutable octet-vector object type. You'll be much happier.
Again I get this feeling like people love to speak in generalizations
on this list :\ Perhaps you know this: In networking/socket stuff
it's useful to reuse a buffer if you know you're receiving frames of a
fixed size, packets of a fixed size -- it can be wasteful and
contentious to allocate for strings to push this data into. I work
with other libraries that expect strings -- this received data isn't
compared against it is parsed (so pointer comparisons are not a huge
gain for pooled strings). This data is almost always unique because
of things like the IP header making it so. Userdata on its own is
pretty inaccessible -- you cannot make comparisons between userdata or
use the functions provided by the string library to parse userdata
directly. Strings are a thin abstraction over userdata -- it feels
like I'm working around an API that should be more accomodating. If I
wanted to minimally change Lua how it is now, I'd make it so userdata
can be used in the same places strings can.
Essentially:
immutable_string1 == immutable_string2 -- would be a pointer comparison
immutable_string1 == mutable_string3 -- would be a memcmp()
I'm somewhat surprised people doing embedded work don't wish userdata
could conform to being a mutable string type in OOM situations.
Modifying a string does mean allocating for it twice..