C++: Optimizing speed with vector/array?

前端 未结 8 1794
半阙折子戏
半阙折子戏 2021-01-02 00:51

I have a nested for-loop structure and right now I am re-declaring the vector at the start of each iteration:

void function (n1,n2,bound,etc){

    for (int          


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 01:44

    Well if you are really concerned about performance (and you know the size of n1 and n2 beforehand) but don't want to use a C-style array, std::array may be your friend.

    EDIT: Given your edit, it seems an std::array isn't an appropriate substitute since while the vector size does not change each iteration, it still isn't known before compilation.

提交回复
热议问题