checking how much ram my program is currently using.

Hello everyone!

I searched all over the internet and i found few functions but non of
them worked like i would want.

Here's code example:
int main() {
long long int r1 = get_rusable();
char *takeram = new char[1000];
long long int r2 = get_rusable();
cout << "result:" << r2 - r1 << endl;
return 0


get_rusable() is imaginary function what am i looking for.
Anyone knows how to do what i want?
Last edited on
Is this for debug purposes?

If so, and you're using Visual Studio, then the debug version of the Microsoft CRT provides _CrtMemCheckpoint which works like you want. But this is just for debug diagnostic purposes.

I have no idea what's provided (if anything) by MinGW or CYGWIN, but as neither of them have a crtdbg.h it's unlikely to be the same mechanism. And I have no idea of the score when it comes to Linux (etc.)

But you could roll your own?

How To Find Memory Leaks

Last edited on
@Homberto, tried those and they didn't work the way i wanted.

@Andywestken, It's not for debug.
My program just wants to check the ram usable sometimes.
Then it knows that what would be its next move.
The post Homberto pointed you at looks pretty exhaustive. If nothing on the list works for you then I think you're at a dead end.

What do you mean by "they didn't work the way i wanted."??

Registered users can post here. Sign in or register to post.