lua-users home
lua-l archive

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


On Tue, Aug 03, 2004 at 05:21:29PM +0200, Michael Roth wrote:
> Hello,
> 
> somewhere in my wrapper I have to clear some values from the registry.
> When I have to clear the values, I don't know if the values were stored
> in the registry or not.
> 
> So my questions are:
> 
> a.) Which one will fragment the registry lesser?

You are correct in thinking that version A will create and then
immediately delete a key, but I'm not sure what you mean by
fragmentation in the registry. AIUI all that will happen in net is that
should the created key collide with another, the free pointer will be
incremented, causing a rehash to happen sooner.

> b.) Is version_B worth the effort?

Probably not.

> c.) Or is version_A just enough because lua_rawset behaves intelligently?

lua_rawset() doesn't behave 'intelligently', but you'll probably have
to do some benchmarks to find out which is actually faster. The
tradeoff is an extra lookup for every key you delete versus the
possibility of a rehash. It probably depends on how many keys you
expect to be nonexistent in relation the the total keys you're
dealing with and the total size of the registry.

I suspect in most cases you'll find there's very little difference.

-- Jamie Webb