This is the mail archive of the mailing list for the Cygwin 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]

RE: finding out how much memory is available with malloc, gcc, cygwin

Hi Jim
   Well in almost all current Oses, each application is allocated a
virtual memory of 2^32 Bytes. This block is divided into many segments
like data, text, bss, stack and heap. 
The max. size of heap depends varies from one application to another as
the other segments vary from one application to another. And also it is
OS dependent. Some OS may restrict it's heap from  growing beyond some
MBs, and some may allow applications to readjust the heap size. (thru
calls similar to unix brk() call).

  OK that's some theory. Coming to your applciation, if the intent is to
find out the "physical memory" present, I think some kernel level
programming is required. Please refer "Linux Device Drivers" By Rubini
of the O'Reilly Team.

But if the intent is to really find out how many bytes can be malloced
by an application, I think the answer will be different on different

Hope this helps.


-----Original Message-----
From: Jim Holder [] 
Sent: Tuesday, August 19, 2003 3:25 AM
Subject: finding out how much memory is available with malloc, gcc,

A program similar to the one listed below works for me on Linux but not
Cygwin.  The idea is to find out how memory I can allocate on the
machine.  The
Cygwin version keeps going (past 700MB), reporting that it has allocated
memory than the machine has.  What am I doing wrong?  Thanks.

#include <stdlib.h>
#include <stdio.h>
int main(void)
    char *p;
    int loop = 1;
    long allocated = 0L;
    const long PIECE = 1000L;
    const long TENMB = 10000000L;
    long nextTenMB = TENMB;

        p = (char*)malloc(PIECE);
        if(p == NULL)
            printf("p == NULL\n");
            loop = 0;
        if(p == (char*)0)
            printf("p == (char*)0\n");
            loop = 0;
        if(loop == 0)
        allocated += PIECE;
        if(allocated >= nextTenMB)
            printf("%ld\n", allocated);
            nextTenMB += TENMB;
    printf("final:  %ld\n", allocated);
    return 0;

Some environment particulars:

    -  cygwin 1.3.19-1
    -  gcc 3.2-3
    -  windows 2000, version 5.0, service pack 4

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Unsubscribe info:
Problem reports:


Information contained in this E-MAIL being proprietary to Wipro Limited is 
'privileged' and 'confidential' and intended for use only by the individual
 or entity to which it is addressed. You are notified that any use, copying 
or dissemination of the information contained in the E-MAIL in any manner 
whatsoever is strictly prohibited.


Unsubscribe info:
Problem reports:

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