Fix #493 array myth

Added comment about performance to SL.con.1
This commit is contained in:
Bjarne Stroustrup 2018-01-01 10:40:45 -05:00
parent 7cfb1d7961
commit 7e5019378b

View File

@ -1,6 +1,6 @@
# <a name="main"></a>C++ Core Guidelines
December 26, 2017
Janualy 1, 2018
Editors:
@ -18558,6 +18558,13 @@ For a variable-length array, use `std::vector`, which additionally can change it
Use `gsl::span` for non-owning references into a container.
##### Note
Comparing the performance of a fixed-sized array allocated on the stack against a `vector` with its elements on the free store is bogus.
You could just as well compare a `std::array` on the stack against the result of a `malloc()` accessed through a pointer.
For most code, even the difference between stack allocation and free-store allocation doesn't matter, but the convenieance and safety of `vector` does.
People working with code for which that difference matters are quite capable of choosing between `array` and `vector`.
##### Enforcement
* Flag declaration of a C array inside a function or class that also declares an STL container (to avoid excessive noisy warnings on legacy non-STL code). To fix: At least change the C array to a `std::array`.