CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2016
    Posts
    24

    vector with same size running very slow than dynamically allocated array Edit topic

    I have an array and vector both of same size and dimension. My code needs set operation to be performed on one of them. Now as i see, in vector their are set operation functions already present, but not for array. Since my array/vector is very big, using array for set operation is slow i think, so i want to use vector, but i dont know why when i run vector with same size program executes very slow. As i found that their is no need of dynamically allocating vectors. So what should i do now? My array is like:

    Code:
    #define sp1(m, n, o) (array1[dim2 * dim3 * m + dim3 * n + o])
    int * array1 = (int *)malloc(dim1 * dim2 * sizeof(int));
    And my vector with fixed size is like:

    Code:
    vector<vector<vector<int> > > p(dim1, vector<vector<int> >(dim1, vector <int>(dim2, dim3)));
    So now how do i make the this vector run faster so than after that i can do set_intersection operation on them easily?
    Last edited by 2kaud; November 20th, 2016 at 05:58 AM. Reason: code tags added

  2. #2
    Join Date
    Nov 2016
    Posts
    24

    Re: vector with same size running very slow than dynamically allocated array Edit top

    Where the delete button in this page, by the way.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: vector with same size running very slow than dynamically allocated array Edit top

    Quote Originally Posted by dinesh999lama View Post
    Where the delete button in this page, by the way.
    Post deletion is done via Edit Post - however the ability to edit posts is initially disabled until a certain number(?) of posts have been made. If you want a specific change to a post, then either request it here or use the 'Report Post' function which sends an email to the moderators who have the ability to edit/delete posts.

    For posts that contain code, please use code tags rather than font changes. Go Advanced, select the formatted code and click'#'.
    Last edited by 2kaud; November 20th, 2016 at 05:59 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: vector with same size running very slow than dynamically allocated array Edit top

    Code:
     ... vector <int>(dim2, dim3)
    This doesn't look right as this means a vector with dim2 elements with each one initialised to value dim3? I suspect the initial sizing of the vectors is not correct and that during usage p is being dynamically resized.

    Consider
    Code:
    vector<vector<vector<int> > > p(dim1, vector<vector<int> >(dim2, vector <int>(dim3)));
    How are you using p?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Nov 2016
    Posts
    24

    Re: vector with same size running very slow than dynamically allocated array Edit top

    to assign the value to vector i'm doing p[i][j][k]=value, and accessing in similar way. and the vector initialization provided by u above is the correct one.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured