Web lists-archives.com

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




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





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

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