On Tue, Jan 31, 2006 at 11:07:07PM -0600, Larry Tordsen wrote:
> Basically, you use malloc when you dont know how big of an area of
> memory you need.  The compiler  allots some memory for your program when
> it is compiled.  If your program steps over the boundry, you get your
> friendly 'segmentation fault' error.

If you step over the boundary of your heap, you get the segmentation
fault exception.

>                                       You can use realloc to reallocate
> your array if you approach the size of your initial region.  I think
> posix says the contents are indeterminate (its changed between c89 and
> c99),

Nope, it is not changing. The pointer you use to access the object
might change, but the old contents will be moved:
   http://www.opengroup.org/onlinepubs/007908799/xsh/realloc.html

(This is SuSv2 but my book on SuSv3 has an identical entry on
realloc.)

>        but i've never seen a compiler handle the realloc in an
> undesireable way (ie you lose the values from your previous malloc).

It is a library function, part of the UNIX API, not a compiler intrinsic.
That's why it is specified by Posix/SuS and not by c89/c99.

florin

> I hope that is clear enough.

-- 
Don't question authority: they don't know either!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://shadowknight.real-time.com/pipermail/tclug-list/attachments/20060201/6329ef80/attachment.pgp