Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Eduardo Ochs <eduardoochs <at> gmail.com>
Subject: A low-level approach to mutable byte-arrays
Newsgroups: gmane.comp.lang.lua.general
Date: Thursday 2nd June 2011 18:26:08 UTC (over 6 years ago)
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:

  http://angg.twu.net/peek/
  http://angg.twu.net/peek/peek.c.html

>From the description in the C file:

  This file implements four very low-level functions.
  They work like this:
       str = peek_(addr, len)
             poke_(addr, str)
    addr = malloc_(len)
             free_(addr)
  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-)

Cheers!
  Eduardo Ochs
  [email protected]
  http://angg.twu.net/
 
CD: 3ms