C++: Optimizing speed with vector/array?

前端 未结 8 1792
半阙折子戏
半阙折子戏 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-02 01:22

    Why not something like that :

    {
        vector< vector > vec(n1, vector(n2));
    
        for (int i=0; i

    Edit: added scope braces ;-)

提交回复
热议问题