For the past few months I've been working on a Visual C++ project to take images from cameras and process them. Up until today this has taken about 65 ms to update the data but now it has suddenly increased significantly. What happens is: I launch my program and for the first 30 or so iterations it performs as expected, then suddenly the loop time increases from 65 ms to 250 ms.
The odd thing is, after timing each function I found out that the part of the code which is causing the slowdown is fairly basic and has not been modified in over a month. The data which goes into it is unchanged and identical every iteration but the execution time which is initially less than 1 ms suddenly increases to 170 ms while the rest of the code is still performing as expected (time-wise).
Basically, I am calling the same function over and over, for the first 30 calls it performs as it should, after that it slows down for no apparent reason. It might also be worth noting that it is a sudden change in execution time, not a gradual increase.
What could be causing this? The code is leaking some memory (~50 kb/s) but not nearly enough to warrant a sudden 4x slowdown. If anyone has any ideas I'd love to hear them!
Edit: Wow, that was fast! Here's the code (minus some maths) which slows down. I know this is a function where the computational time will increase rapidly if you increase the number of lines. The key here is that with the same data this slows down after 30 iterations.
void CameraManager::IntersectLines()
{
// Two custom classes
TMaths maths;
TLine line1, line2;
while(lines.size()>0)
{
// Save the current line
line1 = lines[0];
// Then remove it from the list
lines.erase(lines.begin());
CvMat* aPoint;
for (int i = 0; i<lines.size(); i++)
{
line2 = lines[i];
aPoint = cvCreateMat(1, 4, CV_32FC1);
// Calculate the point of intersection
maths.Intersect(line1.xyz, line2.xyz, line1.uvw, line2.uvw, aPoint);
// Add the point to the list
points.push_back(aPoint);
}
}
}
}