This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]