summaryrefslogtreecommitdiff
path: root/CPP_STYLE_GUIDE.md
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2018-11-29 19:53:28 +0530
committerRich Trott <rtrott@gmail.com>2018-12-04 10:27:40 -0800
commit447b3907c7b19bf53236538cb53968a7c2aca4b2 (patch)
treecd9956980fb797db8f7af0360d94de69a84f1ed7 /CPP_STYLE_GUIDE.md
parent841caef9db88347e5c61668a814ccd5b99fc00a1 (diff)
downloadandroid-node-v8-447b3907c7b19bf53236538cb53968a7c2aca4b2.tar.gz
android-node-v8-447b3907c7b19bf53236538cb53968a7c2aca4b2.tar.bz2
android-node-v8-447b3907c7b19bf53236538cb53968a7c2aca4b2.zip
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: https://github.com/nodejs/node/issues/22977 PR-URL: https://github.com/nodejs/node/pull/24724 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Diffstat (limited to 'CPP_STYLE_GUIDE.md')
-rw-r--r--CPP_STYLE_GUIDE.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/CPP_STYLE_GUIDE.md b/CPP_STYLE_GUIDE.md
index 5099f34ea8..b82ed7cc19 100644
--- a/CPP_STYLE_GUIDE.md
+++ b/CPP_STYLE_GUIDE.md
@@ -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)
@@ -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
@@ -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