-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array documentation #340
Comments
Hi @rivertam, |
Great, thanks @NickNaso! I did try the |
Hi @NickNaso @rivertam, |
@abhi11210646 converting from a JavaScript array to a native array is an expensive operation. OTOH you can use a JavaScript Int32Array as in the following example: https://github.com/gabrielschulhof/node-addon-examples/blob/array_buffer_to_native/array_buffer_to_native/node-addon-api/index.js. On the native side, you can accept the resulting |
Landed the example in node-addon-examples. Let is know if that resolves your questions. |
Hi @gabrielschulhof, it worked this way. thank you. |
For those (like myself) who want a link to the example @mhdawson is referencing: nodejs/node-addon-examples@7124e5f#diff-36c91849c5180ea4227b8c709138a26b |
@rivertam I want update you that the example has been landed in the example repo and eveyone can find it here: https://github.com/nodejs/node-addon-examples/tree/master/array_buffer_to_native/node-addon-api and @gabrielschulhof added some explanations in the array documentation #465 |
Yeah, I think this is exactly what I was looking for at the time. I can't test it or anything because we essentially dropped that project (we had to move to Python for unrelated reasons -- I'm still bitter), but this definitely seems like it covers the concern I had initially. I suppose I'll close this, but I'm not sure what the exact protocol here is so anyone can feel free to reopen. |
So I'm pretty confused about how to use Arrays/TypedArrays using this library. Basically, I'm looking for the equivalent of the
.push
method. I'd also love a way to reserve space in chunks, as I know how big the resulting array is going to be, though that might be too complicated considering V8.The documentation includes a
.Set(int, Value)
with the exampleobj.Set(42, "The Answer to Life, the Universe, and Everything");
. This example is given for Object, not for Array (I can't find anything with Array at all).I tried to do something similar in the code (I'm trying to make an array of arrays):
obj.Set(0, Napi::Array::New(env));
but got the error:
I'm very confused as to why that's ambiguous, but I also suspect it won't update the length properly or at least will be quite inefficient. When I wrap
0
inuint32_t(0)
, it compiles. Either way, the documentation here is pretty lacking and I think an example using arrays efficiently would be very welcome.The text was updated successfully, but these errors were encountered: