variable nested "for" loop

Pages: 12
One thing worth mentioning:- vector initialization takes longer time as compared to array.

For example, for code line 118 above: vector <float> XX(dimension, 0.0);

If I change it to float XX[dimension];

its performance increases, from 23 iterations per second to 31 iterations per second.
Last edited on
That's because in many cases (not all) the vector allocates on the heap.

activecat wrote:
If I change it to float XX[dimension];
This is not standard C++, you must specify array size from a constant. In other words, for your test to be valid, your arrays must be allocated on the heap as well.
This is not standard C++

Isn't this a simple and basic array..?
It is valid C, it is not valid C++. Some C++ compilers support it because they also support C.

1
2
3
4
5
int x = 5;
const int y = 7;

int arr1[x]; //invalid
int arr2[y]; //valid 
Last edited on
I see. Thank you.
Topic archived. No new replies allowed.
Pages: 12