Mail Archives: djgpp/1997/04/25/03:43:55
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!|
---------------------------------------------------------------------
- Raw text -