From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,c617820a3952d228 X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,c617820a3952d228 X-Google-Attributes: gid1014db,public From: cgreen@yosemite.atc.com (Christopher Green) Subject: Re: Why does my C Realloc() fail? Date: 1998/04/10 Message-ID: <6gln7k$8a3@newshub.atmnet.net>#1/1 X-Deja-AN: 342831708 References: <352d36a9.0@calwebnnrp> Organization: Advanced Technology Center, Laguna Hills, CA Newsgroups: comp.lang.c,comp.unix.osf.osf1 In article <352d36a9.0@calwebnnrp>, Biju Srinivasan wrote: >Platform = DEC Alpha (OSF1 V4.0) >Why does my C realloc() fail? >A single malloc works for as big as 134 MBytes. >Realloc fails for a size of 101 MBytes following an alloc of 100 MBytes. >Doesn't realloc claim the space assigned to the original pointer and add >extra space to it? [snip] Typically, realloc() allocates a new block of the requested size, copies the old block to it, then frees the old block and returns the new block. The situation where there is a large free block immediately following the old block is rare; some realloc()'s may be able to take advantage of it, but you can't count on it. In this case, the problem may be that you have exceeded the per-process heap size limit or the paging (swap) file size when realloc() tried to allocate the new block, and that is why realloc() failed. You can raise the per-process limit with ulimit up to some system-specified maximum; you have to get your sysadmin to raise the maximum to go beyond that. Digital UNIX (which still calls itself OSF1 when you invoke uname) has two different swap behaviors. The default behavior is conservative: anytime you allocate memory, there must be free space in the swap file for it. The alternative is optimistic behavior: the system will allo- cate memory freely, but will fail if it has to be swapped and the swap file is already full. See the man page for swapon for details. -- Chris Green Email cgreen@atc.com Advanced Technology Center Phone (714) 583-9119 22982 Mill Creek Drive ext. 220 Laguna Hills, CA 92653 Fax (714) 583-9213