• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _module-pw_containers-vectors:
2
3=======
4Vectors
5=======
6.. pigweed-module-subpage::
7   :name: pw_containers
8
9A vector is a one-dimensional array with a variable length. Pigweed's vector
10type differs from the standard library in that it is backed by a fixed-size
11buffer.
12
13----------
14pw::Vector
15----------
16Vectors must be declared with an explicit maximum size
17(e.g. ``Vector<int, 10>``) but vectors can be used and referred to without the
18max size template parameter (e.g. ``Vector<int>``).
19
20To allow referring to a ``pw::Vector`` without an explicit maximum size, all
21Vector classes inherit from the generic ``Vector<T>``, which stores the maximum
22size in a variable. This allows Vectors to be used without having to know
23their maximum size at compile time. It also keeps code size small since
24function implementations are shared for all maximum sizes.
25
26Example
27=======
28.. literalinclude:: examples/vector.cc
29   :language: cpp
30   :linenos:
31   :start-after: [pw_containers-vector]
32   :end-before: [pw_containers-vector]
33
34API reference
35=============
36The Vector class is similar to ``std::vector``, except it is backed by a
37fixed-size buffer.
38
39.. doxygenclass:: pw::Vector
40   :members:
41
42
43Size report
44===========
45The tables below illustrate the following scenarios:
46
47* The memory and code size cost incurred by a adding a single ``Vector``.
48* The memory and code size cost incurred by adding another ``Vector`` with the
49  same type as the first scenario, but with a different size. As ``Vector``
50  is templated on both type and size, a different size results in additional
51  code being generated.
52* The memory and code size cost incurred by adding another ``Vector`` with the
53  same size as the first scenario, but with a different type. As ``Vector``
54  is templated on both type and size, a different size results in additional
55  code being generated.
56
57.. TODO: b/388905812 - Re-enable the size report.
58.. .. include:: vectors_size_report
59.. include:: ../size_report_notice
60