lua-users home
lua-l archive

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


Hi,

David Kastrup wrote:
> Such strings would not get hashed unless one used them as a table
> index, and they would not get unified or copied either unless
> necessary.

The problematic words are "unless necessary". So how/where do you
decide when the memory holding the string data is no longer valid
and needs to be copied? (Well, a pooling approach might work.)
But what about dangling pointers on the C side from previous
calls to lua_tostring()? And you still need to allocate a fixed
size object on the heap for every lua_pushlightstring(). And then
you have the added complexity of dealing with two different
string types everywhere in the Lua core. I'm not sure this pays
off, especially for small strings, which make up the majority in
most scenarios.

For huge strings (like whole files) a string buffer approach
(using userdata objects) might be more appropriate. But then
you'll face the problem that most library functions expect
strings and won't be able to use this object type. Some ideas
about how to rectify this have been floating around (but one
really needs to avoid copying the data).

OTOH you could try to speed up string hashing (luaS_newlstr).
I've personally given up on this. Either the hash quality
deteriorates too much or the compiler produces slower code.

Bye,
     Mike