Should I worry about memory fragmentation with std::vector? If so, are there ways to help prevent it? I don't always predict for my programs to be running on a PC, they may also be running on embedded devices/game consoles, so I won't always be able to rely on virtual memory.
Then again I believe it would be more efficient to use a dynamically sized array rather than a static array, so that memory would only be allocated if needed. It would also simplify my programs' design process. Are there ways to achieve this efficiently?
Thanks for any advice!
The answer to your worries may be std::deque
. It gives you a similar interface to that of std::vector
, but works better with fragmented memory, since it allocates several small arrays instead of a large one. It is actually less efficient than std::vector
in some aspects, but for your case it may be a good trade-off.