Skip to content

Commit

Permalink
doc: add a note on usage scope of AliasedBuffer
Browse files Browse the repository at this point in the history
Explain usage context and scope of AliasedBuffer API and its
function in the C++ style guide. Provide an example code.

Fixes: nodejs#22977

PR-URL: nodejs#24724
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
  • Loading branch information
gireeshpunathil authored and Trott committed Dec 4, 2018
1 parent 841caef commit 447b390
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CPP_STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [Use explicit pointer comparisons](#use-explicit-pointer-comparisons)
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
* [Avoid non-const references](#avoid-non-const-references)
* [Use AliasedBuffers to manipulate TypedArrays](#use-aliasedbuffers-to-manipulate-typedarrays)
* [Others](#others)
* [Type casting](#type-casting)
* [Using `auto`](#using-auto)
Expand Down Expand Up @@ -257,6 +258,21 @@ class ExampleClass {
};
```

### Use AliasedBuffers to manipulate TypedArrays

When working with typed arrays that involve direct data modification
from C++, use an `AliasedBuffer` when possible. The API abstraction and
the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][].

```c++
// Create an AliasedBuffer.
AliasedBuffer<uint32_t, v8::Uint32Array> data;
...

// Modify the data through natural operator semantics.
data[0] = 12345;
```

## Others

### Type casting
Expand Down Expand Up @@ -382,3 +398,4 @@ even `try` and `catch` **will** break.
[Run Time Type Information]: https://en.wikipedia.org/wiki/Run-time_type_information
[cppref_auto_ptr]: https://en.cppreference.com/w/cpp/memory/auto_ptr
[without C++ exception handling]: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no
[aliased_buffer.h]: https://github.com/nodejs/node/blob/master/src/aliased_buffer.h#L12

0 comments on commit 447b390

Please sign in to comment.