lua-users home
lua-l archive

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


Hi Sean,

On Tue, Mar 24, 2009 at 7:16 PM, Sean Riley <sean@metaplace.com> wrote:
> I have a situation where I am storing potentially 1000’s of lua tables that
> I need to reference quickly from C. One optimal way of doing this seemed to
> be to put them into the array portion of the global table, that way I can
> use LUA_GLOBALSINDEX to easily get at those tables by a single integer
> lookup. But… the global table doesn’t seem to have an array – just a hash
> table, and adding to it with rawseti even with an integer index just puts
> the new values in the hash table.

I am betting your problem is that you are adding indices out of order
(that is, not from 1 to N). If you add a key+value at a random integer
that is not 1, you will end up placing it in the hash table. This will
eventually add up to most of the keys being in the hash part of the
table due to the nature of how the hash part is resized.

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant