Skip to content

Commit 3d1853b

Browse files
gireeshpunathilBridgeAR
authored andcommitted
doc: add a note on usage scope of AliasedBuffer
Explain usage context and scope of AliasedBuffer API and its function in the C++ style guide. Provide an example code. Fixes: #22977 PR-URL: #24724 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
1 parent cc133c4 commit 3d1853b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

CPP_STYLE_GUIDE.md

+17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [Use explicit pointer comparisons](#use-explicit-pointer-comparisons)
2222
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
2323
* [Avoid non-const references](#avoid-non-const-references)
24+
* [Use AliasedBuffers to manipulate TypedArrays](#use-aliasedbuffers-to-manipulate-typedarrays)
2425
* [Others](#others)
2526
* [Type casting](#type-casting)
2627
* [Using `auto`](#using-auto)
@@ -257,6 +258,21 @@ class ExampleClass {
257258
};
258259
```
259260

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+
260276
## Others
261277

262278
### Type casting
@@ -382,3 +398,4 @@ even `try` and `catch` **will** break.
382398
[Run Time Type Information]: https://en.wikipedia.org/wiki/Run-time_type_information
383399
[cppref_auto_ptr]: https://en.cppreference.com/w/cpp/memory/auto_ptr
384400
[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

0 commit comments

Comments
 (0)