lua-users home
lua-l archive

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


For some reason this didn't make it to the list earlier...

From: "Russell Y. Webb" <rw20@cornell.edu>
> > By providing an array type, Lua can preallocate an array of TObjects (or
> > whatever they are) based on the size specified by the user.  To insert
an
> > object into that array is as simple as array[index] = TObject.
Retrieval is
> > equally as simple.  Lua will run far quicker when using indexed access
and
> > make it perform even better in the benchmarks.
>
> Can't an array type be defined from C?  It might not have all the best
> syntactic integration with lua, but having a arraylib.c to add to lua
would
> be great and if everyone used it then it could become standard.  I'd use
it
> in some cases, but don't see any reason to go adding it to the standard
> language now.

Yes, an array type could be defined from C.  To access it, as you
mentioned, would involve C callbacks.  I would wager the overhead for
making the call to the C callback would be larger than the overhead of
the existing hashing mechanism.

A better solution would be actual VM instructions... ARRAYCREATE,
ARRAYGET, and ARRAYSET should be fine.  ARRAYCREATE would create a fixed
size array, based on the size pushed to the stack.  ARRAYGET/SET would
simply take the array pointer and index on the stack and retrieve/set
the value.  Shouldn't be too much slower than C.

A mechanism like this would be vastly superior in speed to a table for
array-style access.

Thanks,
Josh