lua-users home
lua-l archive

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

On Oct 14, 2004, at 20:52, Rici Lake wrote:

On 14-Oct-04, at 2:39 PM, Tom Spilman wrote:

I was considering hashes, but doesn't Lua internally keep a hashed version of the string? Is there a way to get to that? Or can I count on the const char pointer returned from lua_tostring to be the same for the same strings (this sounds really hacky)? As it is now my innermost scripted loops are doing string compares at the binding layer which makes them less efficient
than they could be with a good hash.

You can count on the char pointer to be the same provided the string never gets garbage collected. (i.e., if you keep a reference to the string somewhere.)

The official line is that this is true only whilst the lua string that is passed to lua_tostring remains on the (Lua) stack. In other words Lua reserves the right to implement a moving memory manager. Of course, all the current implementations will never move the string. So it's okay.

David Jones