lua-users home
lua-l archive

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


On Thu, 12 Jul 2007, David Kastrup wrote:
> Tony Finch <dot@dotat.at> writes:
> > On Thu, 12 Jul 2007, David Kastrup wrote:
> >>
> >> I'd still very much prefer a Lua variant which defaults to uninterned
> >> strings _until_ one uses them for indexing.
> >
> > What would be the advantage of that?

Thanks for your interesting answer.

> It would open the possibility for later implementing compacting
> garbage collection of the string pool.  It would also prevent cache
> poisoning (a principal feature of large hashes and string copying).

As I understand it, Lua guarantees that strings won't move while there's a
reference to them on the stack; if this restriction was removed or
weakened then there's no reason that it couldn't use a compacting
collector.

You can only avoid cache poisoning if the string is not copied when it is
handed to Lua, which implies that you'd need a memory ownership and
allocation/freeing convention. So I guess it would be useful for Lua to be
able to pass blobs around without copying, but any time you want to do
anything string-like with them (indexing a table, comparison, appending)
you need to scan the string and so you might as well intern it. But
userdata is effectively a blob so you should be able to do what already.

Tony.
-- 
f.a.n.finch  <dot@dotat.at>  http://dotat.at/
SOUTHEAST ICELAND: NORTHEASTERLY 5 OR 6, OCCASIONALLY 7. SLIGHT OR MODERATE.
RAIN. MODERATE OR GOOD, OCCASIONALLY POOR.