sbrk() on Linux
Qingshan Bie
qsbie@avanticorp.com
Thu Jan 3 18:19:00 GMT 2002
Hi,
I got a problem on reporting mem usage on linux. We use sbrk
to report mem usage on SUN and HP. It works well. But it doesn't give
correct data on linux. The problem is if I allocate a memory > 133000
bytes, the sbrk() doesn't work as expected. Can someone help?
attached is my test code
Thanks,
Qingshan
-------------- next part --------------
#include <unistd.h>
#include <iostream.h>
double sysMemory(void)
{
static char *offs = NULL;
char *th = (char*)sbrk(0);
if (offs != NULL)
return (double) ((unsigned int) (th - offs));
offs = th;
return 0.0;
}
int main()
{
double memUsage = sysMemory();
char * pChar = new char[131000];
memUsage = sysMemory();
cout << "mem usage is " << memUsage << endl;
delete [] pChar;
return 0;
}
More information about the Gcc-help
mailing list