C++ Vector initial capacity

后端 未结 2 1621
暗喜
暗喜 2020-12-20 11:46

I have some code which uses thousands of vectors each vector has only 4 entries, So I want to set the initial size of each vector to 4 so that I can optimize memory usage by

2条回答
  •  太阳男子
    2020-12-20 12:05

    each vector has only 4 entries

    Then you're probably better off with a std::array instead.

    And in case you need 4 elements because you want a mathematical vector, I suggest a struct:

    struct Vector
    {
        Foo x, y, z, w;
    };
    

提交回复
热议问题