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:
1
2
3
4
5
6
7
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
}

result:1000


get_rusable() is imaginary function what am i looking for.
Anyone knows how to do what i want?
Thanks!
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.
https://msdn.microsoft.com/en-us/library/h3z85t43.aspx

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
http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml

Andy
Last edited on
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 stackoverflow.com 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."??

Andy
Topic archived. No new replies allowed.