The vector<MyPoint>
is preferable, because MyPoint
is likely:
- to be smaller than
vector<double>
(you can check this with sizeof
), and/or
- to make fewer allocations. A vector object itself is small, but generally points to data on the heap. It's possible for small vectors to be optimised to avoid the extra allocation by embedding the data in the vector object, but don't count on that, hence
- to have lower overhead of initialization, destruction, and copying.
For example on my 32bit gcc, std::vector<double>
has size 12, while MyPoint
has size 16, but the vector makes the extra allocation. On a 64bit implementation, MyPoint
will almost certainly be the same size, but std::vector
will 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.