lua-users home
lua-l archive

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


If you are REALLY memory constrained you could store the information in a userdata and provide helper C functions to extract portions of it (in effect, treating it as an array. You mentioned userdata as being complex; it really isn't:

Full userdata (the original version) is just a block of memory allocated for you by Lua, and stored in a Lua value. The C Api provides a way to access that memory block, and so in C you can treat it like a normal heap allocated block of memory (except that you cannot free it, that is Luas job).

Light userdata is just Lua keeping a wrapper to a C pointer; you must allocate the memory, and free it when no longer needed (and make sure Lua has no stray pointers left).

In either case, you keep the array in the userdata and write a couple of C functions that you can call from Lua to access elements of the array (get/set, probably all you need). You will need to understand the Lua stack, but that's not all that hard, PiL does a good job of explaining it. If you want to be really fancy, and you use full userdata, you can even attach a metatable, override __index, and then you can use Lua [] syntax to access the array (read only).

--Tim


On Jun 8, 2013, at 3:00 AM, Geoff Smith <spammealot1@live.co.uk> wrote:

Hi Guys
 
Thanks for the further feedback. A few assorted replies to the comments.....
 
I need some pretty precise maths elsewhere in my code, so it was never an option to change conf.h to reduce Lua's default number definition.
 
Yep, I was aware of the feature with lua_createtable() to pre-create the correct number of storage elements, I have used that a fair bit already in smaller tables I have made. If things look too slow, I will have to look at doing it with userdata, to try and optimise the number of bytes passed.
 
To answer the question on specs. I am using an 80Mhz Freescale Coldfire chip, it has got a few Megs of ram allocated for Lua, cant remember the exact figure, but well less than 10 Megs. I am using just bog standard Lua 5.1.5
 
 Why was I passing it to Lua,  when  I said all I wanted was to make a CSV file ? That one is easy to answer. Flexibility !
I have no idea what other folks might want to do with the data ? Heck, I usually don't know what I will end up doing with features and stuff myself a few months down the road, let alone other people :)
 
Getting embedded firmware changed for small tweaks here and there is a pain in the ass, changing a text file to run a tweaked Lua script is  way less hassle.
 
Geoff
 
 
> Date: Sat, 8 Jun 2013 00:53:39 -0300
> From: xxopxe@gmail.com
> To: lua-l@lists.lua.org
> Subject: Re: Fastest way to transfer data from C to Lua ?
> 
> On 07/06/13 22:32, Sean Conner wrote:
> > You mention having some 5,000 samples, which works out to be around
> > 80k (5,000 * 8 (sizeof double) * 2 (two samples)) which would
> > certainly be too large to handle on my first computer (8-bit 6809 with
> > 64K RAM) all my computers since then would be able to handle that
> > amount just fine. For reference, until about mid-2003 I was using a
> > 486 with 32M RAM for serving up my website, and I was using a similar
> > box for development until 2009. So now I'm curious---what *are* the
> > specs of the system you are using? -spc 
> 
> Personally, the smallest available RAM i've had when using Lua was a
> couple Mb worth.
> On the other hand, I was very close to using pbLua (Lua on Lego NXT
> controller), and that would've driven the low bar way lower.
> And then there are the eLua guys...
>