I was wondering if it was faster to have a std::vector<std::vector<double>>where the nested vector always has 2 elements, or is it faster to have a std::vector<MyPoint>where MyPoint is defined like:
struct MyPoint {
double Point[2];
};
Thanks
The
vector<MyPoint>is preferable, becauseMyPointis likely:vector<double>(you can check this withsizeof), and/orFor example on my 32bit gcc,
std::vector<double>has size 12, whileMyPointhas size 16, but the vector makes the extra allocation. On a 64bit implementation,MyPointwill almost certainly be the same size, butstd::vectorwill probably be bigger.Also, a vector represents a variable-sized, ordered container using contiguous memory. So it’s arguably overkill for a size-2 array, since the use of a vector introduces the possibility that the size might change.