This is the mail archive of the cygwin@cygwin.com 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]

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


A program similar to the one listed below works for me on Linux but not under
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 more
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;

    while(loop)
    {
        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)
            break;
        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
http://sitebuilder.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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