Determining the call stack
Does anyone know how to (at run-time) determine the call stack in debug mode?
I have memory leaks going on that my memory checker is picking up, but as the memory is being allocated in functions whose sole purpose is to allocate structures, it is not very helpful unless I know where these parent functions are being called from.
What I want is to store the call stack during memory allocation, so that if that memory is not freed, it will be easier to find the location from which the parent structure is not being deleted.
Searching google gave no good results, as unfortunately all the key-words are so generic that all the matches were not even close.
This should be possible somehow...
You can access the call stack with Visual C++''s debugger. I don''t about any of the other debugger''s.
While in the debugger, right-click on one of the toolbars and click on Call Stack.
While in the debugger, right-click on one of the toolbars and click on Call Stack.
-Prime Evil
Unfortunately however this is not from within the program.
I need to know when memory is allocated the call-stack, and due to the huge amounts of stuff being allocated (I think there are at least 300) entering at different places in the code it is not feasible for me to manually note the stack each time something is allocated.
I need to know when memory is allocated the call-stack, and due to the huge amounts of stuff being allocated (I think there are at least 300) entering at different places in the code it is not feasible for me to manually note the stack each time something is allocated.
April 03, 2001 09:06 AM
Open up notepad and start writing ''em down.
What I always do is initialize each pointer to NULL, then allocate memory for the pointer with new, do everything I need to do with the pointer, and then delete it.
This gets really confusing when you pass pointers around, so you always need to make sure you delete a pointer ONCE.
Most memory leaks are caused by not deallocating allocated memory and the program exiting. Others are random dumps of memory, etc. If you properly allocate your pointers you shouldn''t be having such a problem.
What I always do is initialize each pointer to NULL, then allocate memory for the pointer with new, do everything I need to do with the pointer, and then delete it.
This gets really confusing when you pass pointers around, so you always need to make sure you delete a pointer ONCE.
Most memory leaks are caused by not deallocating allocated memory and the program exiting. Others are random dumps of memory, etc. If you properly allocate your pointers you shouldn''t be having such a problem.
Hmm, seems it didn''t see that last message was from me. Oh well. What memory watcher are you using and are you using Visual C++?
-Prime Evil
I hoped notepad wasn''t the way... :-(
The memory leaks are caused by not freeing up the memory when it should. My memory checker picks them up when the program exits...
So I know where the memory is allocated. I just don''t know where they should be deallocated.
I just ran to check the number of non deleted allocations in a minimum sized chunk of data... crap. 474.
Time to start typing.
The memory leaks are caused by not freeing up the memory when it should. My memory checker picks them up when the program exits...
So I know where the memory is allocated. I just don''t know where they should be deallocated.
I just ran to check the number of non deleted allocations in a minimum sized chunk of data... crap. 474.
Time to start typing.
I am using a memory watcher I made (based on a tutorial that I saw a while back) that watches new/delete/malloc/free/realloc.
It''s thread safe and so on and so forth. Works pretty well.
Programming in visual c++ 6
It''s thread safe and so on and so forth. Works pretty well.
Programming in visual c++ 6
In the above post, I said that you should deallocate the memory you allocated when your done using it. So if you use it throughout the program, deallocate it at the end of the program.
It could also be that your memory watcher is messed up :p.
It could also be that your memory watcher is messed up :p.
-Prime Evil
Sorry, I wasn''t quite clear... overall there is no memory leaks (because my memory checker cleans them out at shutdown).
Thing is I don''t know where the parent allocation functions (like CreateLinkedList) are being called from so I can clean up when I''m finished using them.
All my leaks are coming from two functions... CreateLinkedList and doubleArrayCreate. But these are used all through the program... within other functions for creating structures with linked lists and double arrays... doh.
I need to figure out where these parent functions are being called from, so they can be cleaned up.
Thanks for helping by the way.
Thing is I don''t know where the parent allocation functions (like CreateLinkedList) are being called from so I can clean up when I''m finished using them.
All my leaks are coming from two functions... CreateLinkedList and doubleArrayCreate. But these are used all through the program... within other functions for creating structures with linked lists and double arrays... doh.
I need to figure out where these parent functions are being called from, so they can be cleaned up.
Thanks for helping by the way.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement