Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!csc!csc3!anucsd!neccan!peter From: peter@neccan.oz (Peter Alexander Miller) Newsgroups: comp.lang.c Subject: Re: function pointers and Mac segments Message-ID: <707@neccan.oz> Date: 4 May 90 10:26:10 GMT References: <3545@dogie.macc.wisc.edu> Organization: NEC Information Systems Australia, Canberra Lines: 40 in article <3545@dogie.macc.wisc.edu>, yahnke@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@uunet.uu.net /\/\* CSNET pmiller%neccan.oz@australia ACSnet pmiller@neccan.oz Disclaimer? These guys have no idea what I am on about! D