effect of free()

Barry Margolin barmar at think.COM
Sun Sep 10 04:48:17 AEST 1989


In article <2069 at munnari.oz.au> ok at cs.mu.oz.au (Richard O'Keefe) writes:
>I am asking are there code
>sequences on those machines where (a) the implementor chose to make
>dereferencing NULL trap, but in such a way that ptr1==ptr2 doesn't trap
>on NULLs *AND* (b) the implementor chose to make comparing other invalid
>addresses trap *AND* (c) under the constraint that the invalid address
>chosen for NULL doesn't trap but others do, those code sequences are
>faster than ones that don't trap at all.

I was almost going to answer that I couldn't think of any, but then I
thought of an easy way to implement it.  The machine is one where
loading invalid pointers causes a trap, and where pages or segments
have access modes.  The null pointer would then be implemented as a
valid pointer to a page whose read and write bits were both off.
Loading the null pointer into an address register would not cause a
fault, but indirecting through it would cause a protection violation.

Barry Margolin
Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list