From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13802 invoked by alias); 15 Apr 2010 08:36:54 -0000 Received: (qmail 13786 invoked by uid 22791); 15 Apr 2010 08:36:53 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SARE_MSGID_LONG45 X-Spam-Check-By: sourceware.org Received: from mail-pv0-f175.google.com (HELO mail-pv0-f175.google.com) (74.125.83.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Apr 2010 08:36:49 +0000 Received: by pvb32 with SMTP id 32so579924pvb.20 for ; Thu, 15 Apr 2010 01:36:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.126.12 with HTTP; Thu, 15 Apr 2010 01:36:47 -0700 (PDT) In-Reply-To: References: Date: Thu, 15 Apr 2010 10:17:00 -0000 Received: by 10.141.213.26 with SMTP id p26mr8269235rvq.133.1271320607954; Thu, 15 Apr 2010 01:36:47 -0700 (PDT) Message-ID: Subject: Re: maximum array size? From: Brian Budge To: Anna Sidera Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg00150.txt.bz2 Is this running in Linux? Linux usually behaves optimistically, actually returning a valid pointer from malloc, even when there is not enough memory left in the system to satisfy the request. A good explanation can be found here: http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html On Thu, Apr 15, 2010 at 1:26 AM, Anna Sidera wrote: > Hello, > > I wrote a program in gcc. I compile it with the option -m64. Is there a l= imit in how much memory malloc can allocate? I run the program for differen= t values of some input parameters. The program defines some scalar variable= s and arrays. Then it defines a large array and tries to set a value in an = element of the array. > int **bufferc =3D malloc((inp_par_a*inp_par_b+2)*sizeof(int *)); > int *bufferc_aux =3D malloc((inp_par_a*inp_par_b+2)*(inp_par_c+1)*sizeof(= int)); > int bfc=3D1; > bufferc[bfc]=3Dbufferc_aux+bfc*(inp_par_c+1); > bufferc[bfc][0]=3D0; > At this point sometimes there is no problem but sometimes I get segmentat= ion fault. There is a lot of unused ram in the server when the problem occu= rs. Do you think the problem is due to a bug that I have before defining th= e array? > > Thanks, > Anna >