GeezerVison is showing github.com — doc: add a note on usage scope of AliasedBuffer · nodejs/node@3d1853b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: CPP_STYLE_GUIDE.md +17Lines changed: 17 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
21 | 21 | * [Use explicit pointer comparisons](#use-explicit-pointer-comparisons) |
22 | 22 | * [Ownership and Smart Pointers](#ownership-and-smart-pointers) |
23 | 23 | * [Avoid non-const references](#avoid-non-const-references) |
| 24 | + * [Use AliasedBuffers to manipulate TypedArrays](#use-aliasedbuffers-to-manipulate-typedarrays) |
24 | 25 | * [Others](#others) |
25 | 26 | * [Type casting](#type-casting) |
26 | 27 | * [Using `auto`](#using-auto) |
@@ -257,6 +258,21 @@ class ExampleClass { |
257 | 258 | }; |
258 | 259 | ``` |
259 | 260 |
|
| 261 | +### Use AliasedBuffers to manipulate TypedArrays |
| 262 | + |
| 263 | +When working with typed arrays that involve direct data modification |
| 264 | +from C++, use an `AliasedBuffer` when possible. The API abstraction and |
| 265 | +the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][]. |
| 266 | + |
| 267 | +```c++ |
| 268 | +// Create an AliasedBuffer. |
| 269 | +AliasedBuffer<uint32_t, v8::Uint32Array> data; |
| 270 | +... |
| 271 | + |
| 272 | +// Modify the data through natural operator semantics. |
| 273 | +data[0] = 12345; |
| 274 | +``` |
| 275 | + |
260 | 276 | ## Others |
261 | 277 |
|
262 | 278 | ### Type casting |
@@ -382,3 +398,4 @@ even `try` and `catch` **will** break. |
382 | 398 | [Run Time Type Information]: https://en.wikipedia.org/wiki/Run-time_type_information |
383 | 399 | [cppref_auto_ptr]: https://en.cppreference.com/w/cpp/memory/auto_ptr |
384 | 400 | [without C++ exception handling]: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no |
| 401 | +[aliased_buffer.h]: https://github.com/nodejs/node/blob/master/src/aliased_buffer.h#L12 |