[comp.sys.mac.programmer] What do InitGraf

nick@lfcs.ed.ac.uk (Nick Rothwell) (11/21/88)

A short and sweet question: Why do my programs have to call InitGraf(),
InitTE(), InitDialogs() and all the rest of this stuff?
   A Macintosh sitting in the Finder is running QuickDraw, putting up dialogs,
and so on, so "initialisation" in that sense is surely unnecessary? Does it
make sense to initialise a manager more than once?
   I presume this tells the managers to start using my application heap for
"thinking space" rather than somebody else's (like the Finder's). Is this
so?
   I'm trying to figure out whether code resources, DAs and so on, have to
go through all this or not...
   Or am I just thinking the wrong way?

		Nick.
--
Nick Rothwell,	Laboratory for Foundations of Computer Science, Edinburgh.
		nick@lfcs.ed.ac.uk    <Atlantic Ocean>!mcvax!ukc!lfcs!nick
~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
...while the builders of the cages sleep with bullets, bars and stone,
they do not see your road to freedom that you build with flesh and bone.

levin@bbn.com (Joel B Levin) (11/22/88)

In article <988@etive.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes:
|A short and sweet question: Why do my programs have to call InitGraf(),
|InitTE(), InitDialogs() and all the rest of this stuff?
|   A Macintosh sitting in the Finder is running QuickDraw, putting up dialogs,
|and so on, so "initialisation" in that sense is surely unnecessary? Does it
|make sense to initialise a manager more than once?
(I'm sure you'll get lots of answers...)

Some "global" managers are, in fact, initialized once, e.g. the
resource manager, memory manager, etc ... Inside Mac spells this out
for each appropriate manager ("The application should never need to do
this" type of comment).  Other managers deal with structures and
processes "local" to the application and its heap.  InitGraf
initializes the QD globals for the application, clears the screen to
the default desktop pattern(*), resets the cursor, etc. -- note how
all this always happens when a new application is launched.  So
InitGraf and initialization procedures for all the managers dependent
on QD need to be called every time the application heap is
initialized.

	/JBL

(*) While this does not all happen under MultiFinder, each application
has its own heap and QD globals, so InitGraf is still needed.

UUCP:     {backbone}!bbn!levin		POTS: (617) 873-3463
INTERNET: levin@bbn.com

iand@munnari.oz (Ian Robert Dobson) (11/23/88)

> A short and sweet question: Why do my programs have to call InitGraf(),
> InitTE(), InitDialogs() and all the rest of this stuff?

The Initialization routines build vital data structures in the application
heap (like the QuickDraw global variables, the TextEdit scrap, etc.).  If you
don't call them then the structures won't be there when they are needed and
your program will bomb.
   Every time you quit to the finder or launch an application a new 
application heap is made so the init routines must be called again.

Ian R. Dobson.
University of Melbourne
munnari!iand