[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua strings as "atoms"???
- From: Chris Marrin <chris@...>
- Date: Mon, 16 May 2005 21:28:07 -0700
Rici Lake wrote:
...
There was a discussion about this on the mailing list a while back, and
the definitive answer from a Lua author was that when it says "the
stack", it really means "the stack". That surprised me, too, but the
manual is quite clear.
If the string is stored in the registry, it won't be garbage collected.
But there is no *official guarantee* that it won't move. There is an
*official guarantee* that it won't move if it is on the stack.
Ok, so maybe they were thinking about the now defunct generational
collector. At any rate, is there any officially sanctioned way of
handling "atoms" or the equivalent?
In practice, however, the standard implementation of Lua doesn't use a
moving garbage collector, so the code you present is not going to fail
with the current Lua version, as far as I know.
Ok, I will do an implementation based on this and isolate it so I can
muck with it if things change.
Whether that particular bit of code is faster than doing a pushstring or
not, I don't know. I rather suspect it would be faster, at least for
long strings. However, if you can use upvalues, you will find them to be
faster than registry stashing -- although I rather sadly suspect that
upvalues may not survive through the next n versions of Lua for some
smallish value of n.
I will test it and let you know...
What would upvalues be replaced with? Surely Lua is not abandoning
closures! That is one thing that has gotten Lua a lot of press for being
hip and cutting edge :-)
--
chris marrin ,""$,
cmarrin@arch.sel.sony.com b` $ ,,.
(408) 955-3049 mP b' , 1$'
Sony ,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'