Web lists-archives.com

Memory problems running C programs using GCC in NetBeans/Cygwin on Windows


I am using a 64 bit GCC compiler in NetBeans to compile a series of C
programs which use the GMP multiple precision library to calculate numbers
with varying lengths of zeroes. The programs are called from a shell script
run from NetBeans or using Cygwin on Windows.

What I am finding at run-time is that several of the files report an error
concerning memory usage:

`Zinput for complex out of memory (zero) -2`

Which is generated by the following code:

    void zinput(Zero out) {
        int i;
        ZEROS(out) = ZSIZE(out) = getinteger();
        if ((out->zero = calloc(ZEROS(out), sizeof(Complex))) == NULL) {
            fatal("Zinput for complex out of memory (zero) %d", ZSIZE(out));
        if ((out->mult = calloc(ZEROS(out), sizeof(int))) == NULL) {
            fatal("Zinput for int out of memory (mult) %d", ZSIZE(out));
        for (i = 0; i < ZEROS(out); i++) {
            cinput(ZERO(out, i));
            MULT(out, i) = iinput();

The `getInteger` function called above reads as follows:

    int getinteger(void) {
        char buff[MAX_BUFFER];
        int i;
        int n;        
        /* Strip leading comments and blank lines */
        do {
            fgets(buff, sizeof (buff), stdin);
            i = strspn(buff, " ");
        } while (buff[i] == '#' || buff[i] == '\n');
        if (sscanf(buff + i, "%d", &n) != 1) {
            fatal("Getinteger error (%s)", buff);
        return n;

This code is buried deep within a mountain of undocumented C code originally
written on Unix: it has not been modified at all. There is no documentation
and the writer is not available. sizeof(Complex) returns 48. 

The Windows PC concerned has 8Gb memory and according to the following piece
of C code, the 64 bit version of Cygwin has 2Gb memory available:

    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, char** argv) {
        unsigned int bit = 0x40000000, sum = 0;
        char *x;
        while (bit > 4096) {
            x = malloc(bit);
            if (x)
                sum += bit;
            bit >>= 1;
        printf("%08x bytes (%.1fMb)\n", sum, sum / 1024.0 / 1024.0);
        return (EXIT_SUCCESS);

Given that the programs run without fault in Unix, I am assuming that there
must be an environmental issue concerning memory when running the programs
on Windows. Therefore, can anyone suggest if there is a way to increase
memory to the GCC compiler within NetBeans or for the project I have, or to
use `makefile` options to increase memory?

I am using version 5.4.0 of GCC as given below:

    $ gcc -v
    Using built-in specs.
    Target: x86_64-pc-cygwin

I also do not understand why the memory checker program returns 2Gb.


Martin O'Shea.

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