From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,c617820a3952d228 X-Google-Attributes: gid1014db,public X-Google-Thread: fee84,c617820a3952d228 X-Google-Attributes: gidfee84,public From: eqtr0b@deepforest.org (Exil Q Trob) Subject: Re: Why does my C Realloc() fail? Date: 1998/04/10 Message-ID: <6gjt9v$gmp@cnn.genmagic.com>#1/1 X-Deja-AN: 342604660 References: <352d36a9.0@calwebnnrp> Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII Organization: Leather Gnomes Newsgroups: comp.lang.c,comp.unix.osf.osf1 In article <352d36a9.0@calwebnnrp>, biju@web1.calweb.com says... > >Doesn't realloc claim the space assigned to the original pointer and add >extra space to it? Only if it *can*. It is perfectly legal for an implementation to never even try to do this. >A single malloc works for as big as 134 MBytes. >Realloc fails for a size of 101 MBytes following an alloc of 100 MBytes. I worked on a system, a few years back, where this sequence would have failed. Let's assume that 134MB can work because that's all the free space that the OS has to give the application. So the app asks for 100MB, and the OS gives it a block that big. Then it reallocs for 101MB. That won't fit in the current block -- so ask the OS for a block it will fit in. But the OS has only 34MB available -- can't make 101 from that. Note that there's no mechanism for joining a block previously obtained from the OS to a new block. It seems to me that any such mechanism would be terribly brittle, subject to easy breakage. David G