public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* sbrk() on Linux
@ 2002-01-03 18:19 Qingshan Bie
  2002-01-25 10:21 ` Qingshan Bie
  0 siblings, 1 reply; 2+ messages in thread
From: Qingshan Bie @ 2002-01-03 18:19 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 312 bytes --]

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

[-- Attachment #2: testsbrk.c --]
[-- Type: text/plain, Size: 416 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: sbrk() on Linux
  2002-01-03 18:19 sbrk() on Linux Qingshan Bie
@ 2002-01-25 10:21 ` Qingshan Bie
  0 siblings, 0 replies; 2+ messages in thread
From: Qingshan Bie @ 2002-01-25 10:21 UTC (permalink / raw)
  To: gcc-help

Could anyone help me on this?

Thanks

Qingshan

Qingshan Bie wrote:
> 
> 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;
> }

-- 
----------------------------------------------------------
Qingshan Bie
Avant! Corporation
46871 Bayside Parkway   Phone: (510) 413-7267 (work)
Fremont, CA 94538       Email: Qingshan_Bie@avanticorp.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-01-25 18:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-03 18:19 sbrk() on Linux Qingshan Bie
2002-01-25 10:21 ` Qingshan Bie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).