Skip to content
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

Implement an initial implementation of DataView class #205

Closed
wants to merge 1 commit into from

Conversation

romandev
Copy link
Contributor

This is an initial implementation of DataView class. This change
includes the following things:

  • DataView::New() methods
  • Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  • Tests for them

@romandev
Copy link
Contributor Author

@mhdawson PTAL

@romandev
Copy link
Contributor Author

FYI, I found a bug in upstream. So, I sent a pull request (nodejs/node#17869).

@romandev
Copy link
Contributor Author

romandev commented Jan 2, 2018

Gentle ping :)

@mhdawson
Copy link
Member

mhdawson commented Jan 3, 2018

Just catching up after being away for a few weeks. Will take me a couple more days before I can review.

nullptr /* arrayBuffer */,
&byteOffset /* byteOffset */);
NAPI_THROW_IF_FAILED(_env, status, 0);
return byteOffset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make any sense to get the data once and cache it as opposed to requesting it every time, I think at least some of them will not change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but I thought that it would be better to request the data everytime than spending additional memory. I think that ByteOffset(), ByteLength(), and ArrayBuffer() methods are necessary but I'm not sure if they are very often used. So, isn't it better to reduce memory usage? (Also, if users want to cache it, they can do it themselves.) WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with keeping it simple for now, if we find it makes sense later on we can always add the cache.

napi.h Outdated
size_t ByteOffset() const; ///< Gets the offset into the buffer where the array starts.
size_t ByteLength() const; ///< Gets the length of the array in bytes.

// TODO: Should implement more methods to read/write data into array buffer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain here that this is a first step and support for additional methods is being added incrementally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@mhdawson
Copy link
Member

mhdawson commented Jan 9, 2018

A few comments. One other general thought is that it would be great to start adding the doc at the same time when we add new APIs.

This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them
Copy link
Contributor Author

@romandev romandev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments. One other general thought is that it would be great to start adding the doc at the same time when we add new APIs.

I agree with you totally. But this implementation is still behind macro flag.
Although users can not use this feature yet, it might be confusing if updating the documents. Therefore, I think that updating documents is better when when exposing this API(removing the macro flag). WDYT?

nullptr /* arrayBuffer */,
&byteOffset /* byteOffset */);
NAPI_THROW_IF_FAILED(_env, status, 0);
return byteOffset;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but I thought that it would be better to request the data everytime than spending additional memory. I think that ByteOffset(), ByteLength(), and ArrayBuffer() methods are necessary but I'm not sure if they are very often used. So, isn't it better to reduce memory usage? (Also, if users want to cache it, they can do it themselves.) WDYT?

@mhdawson
Copy link
Member

Makes sense to make sure doc is added before we remove the gating flag.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@romandev
Copy link
Contributor Author

Gentle ping :)

mhdawson pushed a commit that referenced this pull request Jan 18, 2018
This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them

PR-URL: #205
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
@mhdawson
Copy link
Member

Landed as 673b59d

@mhdawson mhdawson closed this Jan 18, 2018
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them

PR-URL: nodejs/node-addon-api#205
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them

PR-URL: nodejs/node-addon-api#205
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them

PR-URL: nodejs/node-addon-api#205
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
This is an initial implementation of DataView class. This change
includes the following things:
  - DataView::New() methods
  - Getters for DataView (ArrayBuffer(), ByteOffset(), ByteLength())
  - Tests for them

PR-URL: nodejs/node-addon-api#205
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants