node-addon-api's buffer-like types pass their backing memory as a raw pointer plus a separate length, both on the way out (Data() + a length accessor) and on the way in (the New/Copy factories). Callers must keep the two values in sync manually, with no bounds information attached to the pointer.
Once C++20 is the minimum supported standard, we should adopt std::span in both directions. These additions are ABI-compatible (existing pointer/length overloads stay), and give callers a single bounds-carrying handle that works with range-based for, <algorithm>, and <ranges>.
This can be an additive change with a C++ version guard.
node-addon-api's buffer-like types pass their backing memory as a raw pointer plus a separate length, both on the way out (
Data()+ a length accessor) and on the way in (theNew/Copyfactories). Callers must keep the two values in sync manually, with no bounds information attached to the pointer.Once C++20 is the minimum supported standard, we should adopt
std::spanin both directions. These additions are ABI-compatible (existing pointer/length overloads stay), and give callers a single bounds-carrying handle that works with range-basedfor,<algorithm>, and<ranges>.This can be an additive change with a C++ version guard.