effect of free()

Gary M. Samuelson garys at bunker.UUCP
Sat Sep 9 01:46:19 AEST 1989


In article <248 at seti.inria.fr> jourdan at minos.inria.fr (Martin Jourdan) writes:
>Someone else already pointed it out, but let me
>make it clear again.  Imagine a segmented memory architecture with
>protections, and imagine that the call to "free" above frees the last
>used block in the segment and that "free" is clever enough to
>determine it and decides to release the segment to the OS, thus making
>the whole segment invalid (this is perfectly conceivable, and not
>forbidden by any ``standard''; actually I'd love to see some
>programs/processes decrease their memory size when they no longer use
>it).  Then merely loading the value of "ptr" in a register to test it
>against 0 will cause a invalid-address trap.

I find this very hard to believe.  Are you being hypothetical, or
is there a machine that really does this?  I can't think of any
justification for causing an invalid-address trap when some value
is put into a register.  The trap should only occur when an attempt
is made to actually use the invalid address.  Suppose I want to
prevent invalid address traps by examining the pointer -- how could
I determine if a pointer contained a valid address, if the trap
occurs as soon as I try to look at the pointer (never mind what it
points to)??

Gary Samuelson



More information about the Comp.lang.c mailing list