Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: CALLOC and MALLOC Message-ID: <7168@brl-smoke.ARPA> Date: 22 Jan 88 21:17:14 GMT References: <11415@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 15 In article <11415@brl-adm.ARPA> V4039%TEMPLEVM.BITNET@CUNYVM.CUNY.EDU (Stan Horwitz) writes: >Why do the basic memory allocation functions CALLOC and MALLOC clear the newly >allocated memory they yield? malloc() doesn't. calloc() stores 0 bytes in the allocated area, which may not be equivalent to 0-valued objects if some of the storage is interpreted as pointers or floating-point data. >I am a novice C programmer and am trying to build dynamic arrays as I >data is received by the program in question, yet each time I add a new >element of memory onto my array, all the previous elements are cleared. I don't know how you're trying to do this; realloc() is used to extend the allocated memory, and it does NOT alter the previous contents, although it may move them to new addresses.