lua-users home
lua-l archive

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


Hi
 
I have an application where I have generated a bunch of ADC samples from a chip that I need to transfer over to Lua.
Each sample comprises of a sample time and an adc value, I have approximately 5000 samples to transfer to Lua.
 
As my CPU is orders of magnitude slower than a typical PC, I am pondering what would be the best way of doing this, as regards simplicity, minimum memory usage, and fastest speed.
 
I discounted userdata as I only ever need to get data in one direction C --> Lua (and also I don't understand userdata too well)
 
So I am looking at doing it via the C lua table api functions. I would have nested tables, but should the inner table be a hash type table or an array type table ?
 
An inner Hash table would give me on the Lua side this nice readable type of syntax
 
myTime =  mySamples[434].time
myValue =  mySamples[434].value
 
 
An Array type inner table would give me  (not quite so readable)
 
myTime =  mySamples[434][1]
myValue =  mySamples[434][2]
 
The second method sounds like it would be faster, and less memory to store on the Lua side. But I wouldn't be surprised if Lua did some tricks for the hash table example where it optimises its key string storage so it doesn't need to store the key strings "time" and "value" 5000 times. So maybe it would be of similar memory cost, and maybe only slightly slower ?
 
Would be interesting if someone more knowlegable could speculate on how they compare ?