Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!apple!apple.com!rmh From: rmh@apple.com (Rick Holzgrafe) Newsgroups: comp.sys.mac.programmer Subject: Re: C function ptrs & Mac mem segments Message-ID: <8018@goofy.Apple.COM> Date: 2 May 90 19:08:06 GMT Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 38 References:<3550@dogie.macc.wisc.edu> <263DD5DE.1BCE@intercon.com> In article <263DD5DE.1BCE@intercon.com> amanda@mermaid.intercon.com (Amanda Walker) writes: > In article <3550@dogie.macc.wisc.edu>, yahnke@vms.macc.wisc.edu (Ross Yahnke, > MACC) writes: > >[about C function pointers] > > Do I ever have to worry about the Mac memory manager purging and > > then reloading this segment thereby possibly causing the address's > > to become invalid? > > I believe that both THINK C and MPW C implement function pointers as > pointers to the jump table entry for the function, not as pointers to > the beginning of the actual code for the function. Since the jump > table is always resident and never moves function pointers won't move. > Also, CODE segments oonly get unloaded if you call UnloadSeg on them > explicitly. > > The thing you do have to watch out for is unloading a segment that > contains a routine that will be called at interrupt time, since calling > LoadSeg at interrupt time would be bad. All perfectly correct. One other thing to watch out for: don't unload a segment containing a routine which is still on the stack. That is: if code in segment A calls a routine in segment B, segment B better not unload segment A. The reason is that the return address on the stack is a real pointer into segment A, and isn't one of these "magical" pointers into the jump table. Often recommended is to keep your main event loop in segment 1 (which, like the jump table, is locked and can't be moved or unloaded), and each time through the loop call UnloadSeg on every other segment. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 77-A | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."