From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: memory allocation: malloc vs. calloc Date: Thu, 24 Apr 1997 12:32:41 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 31 Message-ID: <335F52E9.2CAB@NO.SPAM.cs.com> References: <5jops9$sbc AT lyra DOT csx DOT cam DOT ac DOT uk> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp204.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Michael Meeks wrote: > > I'm lost here, which is the alloc that gets temp. memory from the > stack, and saves fragmentation ? and is there a variant of that that zeros > the memory ? Hehe... loads of *alloc* questions. It's time to confuse the newbies! ;) malloc, calloc, and their relative, xmalloc, allocate memory from the heap (i.e., permanent storage). malloc() is the standard function, calloc() zeroes the memory it allocates, and xmalloc() acts like malloc() but prints an error and exits if it can't get enough memory. alloca() is the function that grabs memory from the stack. Any memory grabbed in this way vanishes when the function exits. alloca() does NOT zero memory, but it's not like you can't do that yourself. Please note that this function can eat up tremendous amounts of stack space, so use it for small structures only or else you'll need to boost your program's stack by setting the _stklen global variable. WARNING: Failure to ensure that you have sufficient stack space can cause your programs to crash in really _strange_ ways. -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com | | God's final message to His Creation: | http://www.cs.com/fighteer | | "We apologize for the inconvenience."| Fight against proprietary | | - Douglas Adams | software - support the FSF!| ---------------------------------------------------------------------