Hi Florian and all,
On Thu, Jun 2, 2011 at 11:56 AM, Florian Weimer wrote:
> I'm interested in defining a lightweight library for mutable byte
> arrays. I'm attaching a draft.
> My goals are these: define something which can be implement reasonably
> efficiently in stock Lua 5.1, that is easy to interoperate with at the
> C level, and which can be optimized by Lua compilers. Eventually, I
> hope that different libraries will be able to exchange data as byte
> arrays instead of strings (where this makes sense), reducing
> allocations and avoiding hashing.
> The C interface is the main reason why the arrays are not resizable:
> Otherwise the address of the underlying memory region could change
> while you cling to a reference of the array object.
> What do you think about this idea?
I know that you should be all thinking on something infinitely more
highlevel-ish that what I am going to show, but I can't resist showing
this!... If one is mostly interested in starting with the mininum and
building a prototype around it, then maybe this could help:
>From the description in the C file:
This file implements four very low-level functions.
They work like this:
str = peek_(addr, len)
addr = malloc_(len)
where "addr" and "len" are integers, and "str" is a string.
The functions are placed in the global namespace.
There is no range checking at all, just like in the old Forth days.
Have fun! 8-)