Vector storage in C++

前端 未结 5 617
轮回少年
轮回少年 2021-02-05 01:08

I wish to store a large vector of d-dimensional points (d fixed and small: <10).

If I define a Point as vector, I think a v

5条回答
  •  没有蜡笔的小新
    2021-02-05 01:38

    vector will store whatever your type contains in contiguous memory. So yes, if that's an array or a tuple, or probably even better, a custom type, it will avoid indirection.

    Performance-wise, as always, you have to measure it. Don't speculate. At least as far as scanning is concerned.

    However, there will definitely be a huge performance gain when you create those points in the first place, because you'll avoid unnecessary memory allocations for every vector that stores a point. And memory allocations are usually very expensive in C++.

提交回复
热议问题