I have a class that goes something like:
class node{// case 1
float points[maxCap][d];
...
}
I can also do it like:
class node{// case 2
float** points;
node(){
points = (float**)malloc(maxCap*sizeof(float*));
if(points)
for(int i=0; i<maxCapacity; i++)
points[i] = (float*)malloc(d*sizeof(float));
else{
cout<<"Unable to get memory"<<endl;
exit(1);
}
}
...
}
They are basically nodes in a tree. I'm creating approximately 500'000 to 1'000'000 of these.
When I search for a point, with every single thing in the search algorithm being the same, case 2 comes out to be approximately 0.2 seconds slower than case 1 (taking average over 3 runs -- although the times are more or less the same for all the 3 runs). Time for case 1 is approx 0.88s
while that for case 2 is approx 1.07s
. Can someone please tell me what's going on here? Shouldn't this be approximately the same?