-
Notifications
You must be signed in to change notification settings - Fork 7
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
Does not work with subarrays #5
Comments
I'd hesitate to call the first example a 'pattern', no offence to its authors intended. It looks like it gets the contents of the underlying buffer, and may not be the right code to match the intention. It's a general area I'm unsure about though, and am asking others, including those who run node.js to consider, and to establish and document what the patterns are. See nodejs/node#8269 I'm hopeful that those with a thorough understanding of V8 and C++ can agree on what the best practice for this is. I've not yet tried the provided hack. If no-one else has done this yet, I suppose that by default it is best practice as well as being a hack. |
Searched the node repo for auto buffer = view->Buffer();
auto contents = buffer->GetContents();
auto data = static_cast<unsigned char*>(contents.Data()) + byte_offset; They cast the underlying buffer to |
I got this to work: void *data = array->Buffer()->GetContents().Data();
size_t offset = array->ByteOffset();
unsigned char *data_offset = static_cast<unsigned char*>(data) + offset;
double *x = reinterpret_cast<double*>(data_offset); |
The first line of that example does not have matching brackets. Having removed an extra bracket at the end, I also get a compilation error:
on the line that corresponds with:
|
Wow that was sloppy pasting on my part, the |
I took the last two lines of your corrected code and condensed it into:
I suggest that would be better as it does not leave the |
Looks good! I'm going to update the code in this repo with the fix and submit a pull request. |
A bug with Node.js is causing the offsets of subarrays to not be registered when using the following patternBelow code does not work with subarrays because theArrayBuffer
offset is not taken into account:This seems to be fixed by using the following hack:
However, it appears to be undefined behaviour in C++. Not sure if I should wait for Node.js to patch the bug or if I should incorporate above into the code.
Ping @metabench.
The text was updated successfully, but these errors were encountered: