Using a vector’s raw data should be just as fast as using a straight memory block. But don’t break the memory cache. Try and work on contiguous memory much as possible. I find it easy to not care or just forget which is the straight memory layout in multidimensional arrays.

Also, I recently found std:span to be pretty useful when using vector data.

std::vector<int> mydata{ 30, 30, 20, 10 };
std::span<int> sp = mydata;

Then use the span as a reference to the data block.

1 Like

If the size requirements are known, use std::array. Comparing with std::vector is apples and oranges, because of the memory management it includes. The old-style nested C arrays don’t have that.
But: +1 for Ben’s recommendation.

1 Like