function pointers and Mac segments

Peter Alexander Miller peter at neccan.oz
Fri May 4 20:26:10 AEST 1990


in article <3545 at dogie.macc.wisc.edu>, yahnke at vms.macc.wisc.edu (Ross Yahnke, MACC) says:
> 
> I'm a little confused about this. I have a Macintosh program
> I'm doing in Think C. In one part I make heavy use of function
> pointers where I init a heap based array with the address's of
> a bunch of different functions. 
> 
> The init code, all of the functions themselves and the routine
> that actually does the referencing (jumping) to the functions
> are all in one segment, but not the main one. 
> 
> Do I ever have to worry about the Mac memory manager purging and
> then reloading the segment thereby possibly causing the address's
> to become invalid? If the init code or the functions or the 
> jumping routine were in different segment would I ever have to
> worry?
The Mac uses a jump table for functions.
All function calls go through this table.
This table is relative to A5, and is never purged.
The table contains either (a) a trap to load in the code segment
or (b) a jump into the code segment (if it is loaded).
Your array of pointers to functions is being filled
with addresses of entries in the jump table.
If you call through one of these function pointers it will
load the segment into memory if necessary first.

In short: no, you don't have to worry about the addresses becoming invalid
or the function not being in memory.

BTW I use Think C 4.0 myself.

Hope this helps.

Regards
Peter Miller       UUCP    {uunet,mcvax,ukc}!munnari!neccan.oz!pmiller
                   ARPA    pmiller%neccan.oz at uunet.uu.net
/\/\*              CSNET   pmiller%neccan.oz at australia
                   ACSnet  pmiller at neccan.oz
Disclaimer?  These guys have no idea what I am on about!
D



More information about the Comp.lang.c mailing list