daf@genrad.com (David A. Fagan) (02/16/89)
In C, global data is compiled as part of the executable image, right? So what happens when the Memory Manager decides it's time to clean house? Some guesses: 1) Code segments aren't simply purged, they're saved back to disk 2) Global data is clobbered when the segment in which it was declared is unloaded. 3) Mac compilers are smart enough to keep all global data in seperate resources which cannot be purged. My money is on #3, does anyone know for sure? Thanks, email is sufficient. Dave Fagan genrad.otter.daf
siegel@endor.harvard.edu (Rich Siegel) (02/17/89)
In article <17278@genrad.UUCP> daf@genrad.UUCP (David A. Fagan) writes: >In C, global data is compiled as part of the executable image, right? Nope. Global data is stored in the global data area, which is referenced by negative offsets from A5. At link time, the correct offsets are fixed up by the linker. None of this is affected by runtime changes. --Rich Rich Siegel Staff Software Developer THINK Technologies Division, Symantec Corp. Internet: siegel@endor.harvard.edu UUCP: ..harvard!endor!siegel Phone: (617) 275-4800 x305
levin@bbn.com (Joel B Levin) (02/17/89)
In article <17278@genrad.UUCP> daf@genrad.UUCP (David A. Fagan) writes: |In C, global data is compiled as part of the executable image, right? |So what happens when the Memory Manager decides it's time to clean house? For normal programs / applications: While running, globals are not part of any segment; they are below (lower address than) the jump table (CODE 0) in memory, with A5 pointing to the boundary; the stack is below the globals. In the application itself it is the job of the application to initialize the global area when it starts up. The development system will build global initialization in, generally. In MPW, the linker generates a segment called something like %A5Init which performs this function. The initial values and strings are stored (generally) as part of this segment. The application can unload this segment when initialization is done (any time after "main()" has started, in C). Think C programs often have DATA, STRS, and other resources hanging around; maybe this is where they keep initial values for globals. I don't own that system, so this is just a guess. | Some guesses: | 1) Code segments aren't simply purged, they're saved back to disk Segments are not "saved back to disk" -- they are read in when called, and may be "unloaded" when they are done, after which the memory manager may reclaim their space if it wants. | 2) Global data is clobbered when the segment in which it was declared | is unloaded. No. | 3) Mac compilers are smart enough to keep all global data in seperate | resources which cannot be purged. The initialization values for globals (and string constants) may be kept that way by some systems, but the global variables themselves sit in memory. Of course, the programmer may create variable storage in the heap and initialize it, use it, and dispose of it any way she likes (just like using calloc etc.). Disclaimer: Any of the above might be wrong. It is certainly no one's opinions but my own. /JBL UUCP: {backbone}!bbn!levin POTS: (617) 873-3463 INTERNET: levin@bbn.com
tim@hoptoad.uucp (Tim Maroney) (02/17/89)
In article <17278@genrad.UUCP> daf@genrad.UUCP (David A. Fagan) writes: >In C, global data is compiled as part of the executable image, right? No. >So what happens when the Memory Manager decides it's time to clean house? Nothing, as far as global data are concerned. They are stored in a segment of memory created by the _Launch trap outside the application heap zone. Globals and the memory manager don't interact, except of course that globals often point to memory manager data structures. This is as true of static variables as extern variables -- the only real difference is that static variables are only visible in the routine or source file in which they are declared. They're stored the same as externs. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "I have recently been examining all the known superstitions of the world, and do not find in our particular superstition (Christianity) one redeeming feature. They are all alike founded on fables and mythology." -- Thomas Jefferson