Which one is faster?

I was wondering if there is std::vector<std::vector<double>>where the nested vector always has 2 elements, or is it faster to have std::vector<MyPoint>where MyPoint is defined as:

struct MyPoint {
  double Point[2];
};

thank

+3
source share
4 answers

vector<MyPoint>preferable because MyPointmost likely:

  • less vector<double>(you can check this with sizeof) and / or
  • to make fewer distributions. The vector object itself is small, but usually indicates heap data. Small vectors can be optimized to avoid additional isolation by embedding data in a vector object, but do not count on it, therefore
  • , .

, 32- gcc, std::vector<double> 12, MyPoint 16, . 64- MyPoint , std::vector, , .

, , . , , , -2, .

+11

, : std::vector<MyPoint>? , . , , .

MyPoint std::pair<double, double>.

+5

, , ( , ). struct MyPoint { double x, y; };.

+1

std::vector<MyPoint> ? , .

0

Source: https://habr.com/ru/post/1754153/


All Articles