As has already been discussed in Chapter 6, Memory Management, dynamic memory allocation should be avoided in real-time systems because generic memory allocators are not time-bound. While, in most cases, memory allocation does not take much time, it is not guaranteed. It is not acceptable for real-time systems.
The most straightforward way to avoid dynamic memory allocation is to replace it with static allocation. C++ developers often use std::vector to store sequences of elements. On account of its similarity with C arrays, it is efficient and easy to use and its interface is consistent with other containers in the standard library. Since vectors have a variable number of elements, they use dynamic memory allocation extensively. In many situations, however, the std::array class can be used instead of std::vector. It has the same interface...