Just account for all your variables and memory allocations. The sizeof() operator can come in handy here. You can also profile the memory usage of your program in real time by using tools such as valgrind.
There is nothing in the C Standard about how to find out stack and heap depth. Although stack and heap are ubiquituous, I'm not even sure the C Standard mandates their existence.
You have to look for special-purpose tools. A good place to start is your compiler vendor.
There is nothing in the C Standard about how to find out stack and heap depth. Although stack and heap are ubiquituous, I'm not even sure the C Standard mandates their existence.
You have to look for special-purpose tools. A good place to start is your compiler vendor.
On a 32bit machine the following program uses a stack of 8 bytes and a heap of 2 bytes:
[code=c]
int main()
{
int a = 5; // 4 bytes for int
char * b = new char[2]; // 4 bytes for pointer, 2 bytes for array
delete [] b;
return 0;
}
[/code]Now, how much system memory a program actually uses is a different matter. Additionally, libraries may certainly use stack and heap space which can be hard to account for, that's why I suggest using one of the many memory profilers out there like valgrind.
Comment