home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!auspex-gw!guy
- From: guy@Auspex.COM (Guy Harris)
- Newsgroups: comp.unix.programmer
- Subject: Re: realloc question
- Message-ID: <16608@auspex-gw.auspex.com>
- Date: 24 Jan 93 20:27:46 GMT
- References: <9301241809.AA13273@ha12.eng.ua.edu>
- Sender: news@auspex-gw.auspex.com
- Organization: Auspex Systems, Santa Clara
- Lines: 44
- Nntp-Posting-Host: auspex.auspex.com
-
- > Note: The realloc protocol is provided for source code compata-
- > bility with old System V applications and should be avoided in
- > new applications.
- >
- >Question: Is there an equivalent function for realloc? Or, should
- >I code my own realloc?
-
- No, because the above statement from the AIX "malloc" man page is *not*
- saying that the "realloc()" *routine* is provided for source-code
- compatibility with old System V applications (and yes, the man page on
- an AIX 3.2 system here really *does* misspell "compatibility"!); there's
- no way IBM could get away with nuking "realloc()", given that it's in
- the ANSI C standard.
-
- The preceding paragraph says:
-
- The realloc subroutine supports the old realloc protocol wherein
- the realloc protocol returns a pointer to a previously freed
- block of memory if that block satisfies the realloc request. The
- realloc subroutine searchs a list, maintained by the free subrou-
- tine, of the ten most recently freed blocks of memory. If the
- list does not contain a memory block that satisfies the specified
- Size parameter, the realloc subroutine calls the malloc subrou-
- tine. This list is cleared by calls to the malloc, calloc, or
- realloc subroutines.
-
- *That*'s the old protocol to which it's referring; i.e., with the
- traditional UNIX memory allocator, you could grow a block of mallocated
- memory by doing:
-
- free((char *)pointer_to_block);
- pointer_to_block = (thing *)realloc((char *)pointer_to_block,
- new_size_of_block);
-
- and the pointer you got back from "realloc()" would point to a block
- that contained the same data that was in the block you freed in the
- "free()" call.
-
- What IBM is saying is that *new* applications should, instead, do:
-
- pointer_to_block = (thing *)realloc((char *)pointer_to_block,
- new_size_of_block);
-
- to grow the block, *without* doing the "free()".
-