variable nested "for" loop

Pages: 12
Apr 3, 2013 at 2:15am
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 Apr 3, 2013 at 2:19am
Apr 3, 2013 at 2:23am
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.
Apr 3, 2013 at 2:51am
This is not standard C++

Isn't this a simple and basic array..?
Apr 3, 2013 at 2:54am
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 Apr 3, 2013 at 2:55am
Apr 3, 2013 at 3:01am
I see. Thank you.
Topic archived. No new replies allowed.
Pages: 12