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?
Re: vector with same size running very slow than dynamically allocated array Edit top
Where the delete button in this page, by the way.
Re: vector with same size running very slow than dynamically allocated array Edit top
Quote:
Originally Posted by
dinesh999lama
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'#'.
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?
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.