[Dev-C++] The final final stack counting code
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-05-10 16:32:03
|
This is the final stack counting ANSI C++ compliant code with the
maximum precision i can make. Sorry for the many postings:
#include <iostream>
void stack()
{
using namespace std;
// Variable is created on the stack permanently and
// keeps its value between stack() calls (a nightmare
// for concurrency).
static unsigned long counter=0;
// sizeof(void *) to remove the size of the pointer the function call
// occupies itself on the stack
char buffer[1024-sizeof(void *)];
counter++;
// -sizeof(counter) to remove the size of the static variable
// counter. -sizeof(void *) to remove the size of the pointer of
main()
// in the stack.
cout<<"Allocated approximately "<<counter-sizeof(counter)-sizeof(void
*);
cout<<" KB of stack before i die\n";
stack();
}
int main()
{
stack();
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|