Break after certain memory limit hit
Is there a way to have visual studio break a c++ project if the exe reaches a certain memory limit? Say if 200mb is used by the exe, then it wil开发者_如何学编程l break and show me the line of code it is at.
Are you talking about the working set size or heap memory? Heap memory is easy: The debugging VC++ Runtime has _CrtSetAllocHook, which calls a user supplied function on every memory allocation/reallocation/free call.
http://msdn.microsoft.com/en-us/library/820k4tb8.aspx
You could install the hook and then sum the memory allocations. If you hit your threshold value, you can call _debugbreak() to drop into the debugger.
精彩评论