Break after a certain memory limit

Is there a way for a visual studio to crash a C ++ project if exe reaches a certain memory limit? Say, if 200mb is used by exe, then it will break and show me the line of code in which it is located.

+4
source share
1 answer

Are you talking about the size of the working set or the heap memory? Heap memory is simple: debugging VC ++ Runtime has _CrtSetAllocHook, which calls a function provided by the user with each allocation / reallocation / free memory call.

http://msdn.microsoft.com/en-us/library/820k4tb8.aspx

You can set the hook and then summarize the memory allocation. If you hit your threshold, you can call _debugbreak () to go to the debugger.

+3
source

Source: https://habr.com/ru/post/1369032/


All Articles