Re: FFI methods for userdata objects

  • From: Peter Colberg <peter@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 6 Sep 2012 12:12:28 -0400

On Thu, Sep 06, 2012 at 11:54:15AM -0400, Simon Cooke wrote:
> Mike Pall <mike-1209@xxxxxxxxxx> wrote:
> > Simon Cooke wrote:
> >> My specific use case is a class for large arrays (basically a C++
> >> std::vector<T>) using __call to read elements and __newindex to write.
> >
> > Ok, if you need this is for interoperability. But you realize it
> > would be much faster to use a plain FFI data structure? This
> > doesn't need any C calls to index it.
> >
> 
> This is strictly a quick fix to get significantly better indexing
> performance from the Lua side while maintaining interoperability with
> existing C++ data structures and calls to wrapped C++ extension
> modules. For new developments I'm using FFI exclusively as you
> suggest, but this application predates the release of the FFI library
> and adapting to use it fully will require significantly more effort.

Assuming you are using the std::vector in a loop, couldn't you
retrieve the raw pointer just once, e.g., by calling a C method that
returns &*myvec.begin(), and use that pointer to access the vector?

Peter

Other related posts: