You can easily get the memory usage of the current process using workingset64
However I could not find any event like OnMemUsageChanged so I can display a little mem usage meter that displays live/real time the mem usage value. Updating in a timer every second can be done but looks inefficient.
Is there anyway I can get an event or callback every time the mem usage changes ? thank you
No, mapping virtual memory to RAM is a very low level operating system kernel operation. It cannot afford doing something as expensive as running user level code to generate the notification. And much worse: ensuring that this user level code is mapped to RAM as well could undo the mapping operation in the first place. Only polling is an option.
You have to watch out for memory statistics like this. WorkingSet is a pretty random number that is heavily affected by what other code is running on the machine. Pages of your program will be unmapped when the RAM they occupy is needed to run this other code. Simply minimizing the main window of your app has an effect, Windows takes that as a hint that you won’t be using the program for a while and it aggressively trims the working set size to make room for other programs you are probably going to use next.