I am using valgrind to find memory leaks on my program however it is taking a long time and its loading. When I run the program without valgrind it takes second, what is the problem and what should I look for in the code.
Asked
Active
Viewed 7,161 times
2
-
Are you allocating memory to a whole bunch of different places, or doing some other odd thing? The answer below is accurate, a program will run much slower with valgrind monitoring it, but hours compared to seconds is a little odd, at least in my experience, which is why I ask if you're doing something odd. – prelic Nov 25 '12 at 02:23
-
I could see a tight loop or some type of deeply recursive algorithm where you're constantly working the stack, possibly with pointers being allocated/deallocated every time with each call, causing this type of issue. If there is a runtime error, he should probably place some markers in his program to make sure suitable progress is being made an there isn't a hang-up somewhere. – Jason Nov 26 '12 at 02:10
-
Try running valgrind with --db-attach=yes, then ctrl-c the program after several minutes and see what it's doing. – Mike Andrews Nov 26 '12 at 15:21
1 Answers
4
There is no problem as far as I can see unless you can verify an infinite loop or some other run-time error ... Valgrind basically acts like a virtual machine or virtual execution environment running the program, watching all variables, memory allocations, etc., etc. and therefore will run quite a bit slower than native code. You'll get the same effect if you ran your program inside a debugger like gdb
and set it to watch every writable memory location.

Jason
- 31,834
- 7
- 59
- 78
-
But the program completes in seconds...and its already 30 minutes. Is it normal if it takes hours? – Nabmeister Nov 25 '12 at 02:11
-
Well, you can check for infinite loops, etc. but I've seen behavior like this before. If your program is fully running, but just very slowly, my posted answer is typically the reason why. – Jason Nov 25 '12 at 02:13