This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
sbrk() on Linux
- From: Qingshan Bie <qsbie at avanticorp dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 03 Jan 2002 18:19:32 -0800
- Subject: sbrk() on Linux
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
#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;
}