public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Memory problems running C programs using GCC in NetBeans/Cygwin on Windows
       [not found] <8punym7avg33ox0kq30bjlxb.1490165447681@email.android.com>
@ 2017-03-22 16:03 ` Marco Atzeri
  2017-03-23  9:41   ` Martin O'Shea
  0 siblings, 1 reply; 4+ messages in thread
From: Marco Atzeri @ 2017-03-22 16:03 UTC (permalink / raw)
  To: Martin O'Shea, cygwin

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

please reply on the mailing list and
use bottom post for replies as standard practice.

On 22/03/2017 07:50, Martin O'Shea wrote:
> Thanks for the response but can I ask that you clarify what you mean?
>
> I am something of a Cygwin newbie.
>>
>> I also do not understand why the memory checker program returns 2Gb.
>
> 2Gb is the largest block available.
> As you never use free you have reserved ~ 4Gb

Too early in the morning for me. It failed at 2Gb

The modified version will clarify the point I was aiming to.
It runs the request 5 times from 4K to max block available

     7ffe0000 bytes (2047.9Mb)
     60000000 bytes (1536.0Mb)
     40000000 bytes (1024.0Mb)
     40000000 bytes (1024.0Mb)
     40000000 bytes (1024.0Mb)
    640040000 bytes (25600.2Mb)


so the largest block available the first time is almost 2GB,
the second time the largest block is 1.5 GB
and all the rest is 1Gb, however the overall memory allocated
was ~ 25 Gb on a X86_64 machine with just 8GB of physical RAM.

I can not reserve a single block of 25 GB but I can reserve
a lot of smaller blocks.

The limitation on single block max size is likely due to the
underlying Windows system.

Regards
Marco






[-- Attachment #2: max_memory-3s.c --]
[-- Type: text/plain, Size: 1150 bytes --]

#include <stdlib.h>
#include <stdio.h>
int main()
{
  size_t bit=0x40000000, sum=0, total=0;
  char *x;
  
  while (bit > 4096) 
  {
    x = malloc(sum);
    if (x){
	total += sum;
    	sum += bit;
    }
    bit >>= 1;
  }
  printf("%12lx bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);
  bit=0x40000000, sum=0;

  while (bit > 4096)
  {
    x = malloc(sum);
    if (x){
	total += sum;
        sum += bit;
    }
    bit >>= 1;
  }
  printf("%12lx bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);
  bit=0x40000000, sum=0;

  while (bit > 4096)
  {
    x = malloc(sum);
    if (x){
        total += sum;
        sum += bit;
    }
    bit >>= 1;
  }
  printf("%12lx bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);

  while (bit > 4096)
  {
    x = malloc(sum);
    if (x){
        total += sum;
        sum += bit;
    }
    bit >>= 1;
  }
  printf("%12lx bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);

  while (bit > 4096)
  {
    x = malloc(sum);
    if (x){
        total += sum;
        sum += bit;
    }
    bit >>= 1;
  }
  printf("%12lx bytes (%.1fMb)\n", sum, sum/1024.0/1024.0);
  printf("%12lx bytes (%.1fMb)\n", total, total/1024.0/1024.0);

  return 0;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


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

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

* RE: Memory problems running C programs using GCC in NetBeans/Cygwin on Windows
  2017-03-22 16:03 ` Memory problems running C programs using GCC in NetBeans/Cygwin on Windows Marco Atzeri
@ 2017-03-23  9:41   ` Martin O'Shea
  0 siblings, 0 replies; 4+ messages in thread
From: Martin O'Shea @ 2017-03-23  9:41 UTC (permalink / raw)
  To: cygwin

Marco

Thanks for the information. It has proved helpful. And apologies posting to the wrong email address.

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

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

* Re: Memory problems running C programs using GCC in NetBeans/Cygwin on Windows
  2017-03-22  1:34 Martin O'Shea
@ 2017-03-22  6:20 ` Marco Atzeri
  0 siblings, 0 replies; 4+ messages in thread
From: Marco Atzeri @ 2017-03-22  6:20 UTC (permalink / raw)
  To: cygwin

On 22/03/2017 00:06, Martin O'Shea wrote:
> Hello
>
> 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.
>

>
> 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.
>     COLLECT_GCC=gcc
>     COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/lto-wrapper.exe
>     Target: x86_64-pc-cygwin
>
> I also do not understand why the memory checker program returns 2Gb.

2Gb is the largest block available.
As you never use free you have reserved ~ 4Gb


> Thanks
>
> Martin O'Shea.

Regards
Marco

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

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

* Memory problems running C programs using GCC in NetBeans/Cygwin on Windows
@ 2017-03-22  1:34 Martin O'Shea
  2017-03-22  6:20 ` Marco Atzeri
  0 siblings, 1 reply; 4+ messages in thread
From: Martin O'Shea @ 2017-03-22  1:34 UTC (permalink / raw)
  To: cygwin

Hello

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.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/lto-wrapper.exe
    Target: x86_64-pc-cygwin

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

Thanks

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

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

end of thread, other threads:[~2017-03-23  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <8punym7avg33ox0kq30bjlxb.1490165447681@email.android.com>
2017-03-22 16:03 ` Memory problems running C programs using GCC in NetBeans/Cygwin on Windows Marco Atzeri
2017-03-23  9:41   ` Martin O'Shea
2017-03-22  1:34 Martin O'Shea
2017-03-22  6:20 ` Marco Atzeri

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).