0

I am trying to pass an array from a node app to an add-on I have build using node-gyp. As performance is a major concern in this case, I am trying to use the most efficient ways to pass and parse the data. The issue I am encountering is passing an array and then converting it from a v8 array to a regular float* . The best solution I could find is:

  • Grab the argument Local<Array> buffer = args[0].As<Array>();
  • Iterate over it using a for loop to extract the data, like so:

    for(int i=0 ; i < 512 ; i++) bufferArray[i] = buffer->Get(i)->NumberValue();

Where bufferArray is an float array that I instantiated earlier. Then, I pass bufferArray to my c++ library that through a function that accepts a float*.

Is there a better solution than this?

nevos
  • 907
  • 1
  • 10
  • 22
  • Is there an internal, contiguous array that is wrapped in `Local`? If so, then determine if you can get to it. If so, then pass that address to the C++ function. – PaulMcKenzie Jul 16 '15 at 09:38
  • @PaulMcKenzie hmmm I'm not quite sure what you mean, can you please explain it a bit more? – nevos Jul 16 '15 at 09:41
  • Somewhere in `Local` is an internal buffer that holds the data. Get to that buffer, and there is no need to call `Get`. Just pass a pointer to this buffer. – PaulMcKenzie Jul 16 '15 at 09:51
  • That's the thing, I can't find how to get it. Do you know how? I searched in [the v8 `Local` docs](http://izs.me/v8-docs/classv8_1_1Local.html) and the [v8 `Array` docs](http://izs.me/v8-docs/classv8_1_1Array.html). – nevos Jul 16 '15 at 10:20

0 Answers0