[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua strings as "atoms"???
- From: Rici Lake <lua@...>
- Date: Mon, 16 May 2005 23:09:09 -0500
On 16-May-05, at 11:00 PM, Chris Marrin wrote:
Ok, RTFM makes it a bit more clear. When it says "stack" it really
means as long as the string exists as a valid object inside the Lua
VM, right. It implies this where it talks about the registry (3.18).
So that means I should be able to do this:
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.
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.
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.
R.