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

doc: added some warnings for buffer and array buffer factory method. #929

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/array_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ The `Napi::ArrayBuffer` instance does not assume ownership for the data and
expects it to be valid for the lifetime of the instance. Since the
`Napi::ArrayBuffer` is subject to garbage collection this overload is only
suitable for data which is static and never needs to be freed.
This factory method will not provide the caller with an opportunity to free the
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
data when they get garbage-collected. If you need to free the data retained by
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
the `Napi::ArrayBuffer` object please use other variants of the
`Napi::ArrayBuffer::New` factory method that accept `Napi::Finalizer` a
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
function that will be invoked when `Napi::ArrayBuffer` object has been
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
destroyed.

```cpp
static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength);
Expand Down
7 changes: 6 additions & 1 deletion doc/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ Wraps the provided external data into a new `Napi::Buffer` object.
The `Napi::Buffer` object does not assume ownership for the data and expects it to be
valid for the lifetime of the object. Since the `Napi::Buffer` is subject to garbage
collection this overload is only suitable for data which is static and never
needs to be freed.
needs to be freed.
This factory method will not provide the caller with an opportunity to free the
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
data when they get garbage-collected. If you need to free the data retained by the
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
`Napi::Buffer` object please use other variants of the `Napi::Buffer::New` factory
method that accept `Napi::Finalizer` a function that will be invoked when
NickNaso marked this conversation as resolved.
Show resolved Hide resolved
`Napi::Buffer` object has been destroyed.
NickNaso marked this conversation as resolved.
Show resolved Hide resolved

```cpp
static Napi::Buffer<T> Napi::Buffer::New(napi_env env, T* data, size_t length);
Expand Down