[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Fastest way to transfer data from C to Lua ?
- From: David Heiko Kolf <david@...>
- Date: Fri, 07 Jun 2013 22:42:53 +0200
Geoff Smith wrote:
> This is one example where Lua not having an option for 8 or 16 bit
> number sizes will cost me badly on execution time. I hope Roberto is
> still thinking optional smaller number types is a good feature for 5.3.
> I am more enthusiastic about that one possible change than all the
> features in 5.2 put together. Anyway I digress.
There is already a compile-time option in luaconf.h to use other number
formats, but that would affect all numbers used by Lua. (And it might
disturb the math library).
If you want to use different numbers just for your array you would need
to go the slightly harder way of implementing the array as userdata.
(Or I guess LuaJIT would be an alternative). An example for such an
userdata can be found in <http://www.lua.org/pil/28.1.html>.
> Now I have read the replies, I am favouring the individual big tables
> myTime = mySamples.time
> myValue = mySamples.value
> This is quite readable, so I will code it up soon and see how fast it
> is. I will post some numbers when I have done it for reference.
One further hint for speed, if you are creating the table in C and you
know the total number of elements when creating the table, you can use
the function lua_createtable(L, narr, 0) where narr would be your
variable containing your array size. Then the necessary memory would be
allocated right from the start and Lua doesn't need to realloc the
memory (which might involve lots of copying).