From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,d2d94298017fc327 X-Google-Attributes: gidfee84,public From: Al Simons Subject: Re: Question on 'realloc' function Date: 1997/10/01 Message-ID: <34325973.461D@zk3.dec.com>#1/1 X-Deja-AN: 277040439 References: <3420AB59.167E@resptk.bhp.com.au> Reply-To: simons@zk3.dec.com To: Joe Spanicek Organization: DIGITAL UNIX Development Environment Newsgroups: comp.unix.osf.osf1 Joe Spanicek wrote: > If a call to 'realloc' fails and returns a NULL to indicate it has, > what actually happens to the original memory block passed as a pointer > reference into the function ?? When a call to realloc fails and returns NULL, the original has not been modified. It ia available to the application to continue processing as the application sees fit. Some caveats: When the application calls realloc(old, 0) this is considered a synonym for free(old). realloc() returns NULL, and the old memory is free. When free is called on a chunk of memory 632 bytes or smaller, it is placed in a special way station for one additional free operation. While it is in the waystation, it can be successfully realloc'd. THIS IS NOT SUGGESTED PRACTICE! This is a hack to accommodate a large class of buggy programs. There is no waystation for blocks above 632 bytes in size. Once freed, they have had portions of the block overwritten with bookkeeping information. In the first case (<= 632 bytes), the realloc can succeed. In the latter case (>632 bytes) the realloc will fail, the memory pointed to by your pointer has not been touched by the realloc operation, but it HAS ALREADY BEEN MODIFIED by the free operation. Al Simons DIGITAL UNIX Development Environment simons@zk3.dec.com