close this bookTidBITS#82   
View the documentINIT Introduction
View the documentDiving In
View the documentOnto INITs!
View the documentThe Killer INIT
View the documentLittle Known Facts
View the documentSumming It Up
View the documentFoot Notes

Onto INITs!

If a program wants to achieve some kind of a global effects (like QuicKeys allowing you to define macros that work in any program), it has to find out how to graft itself into your system and keep a portion of memory for itself that will stay around even when a program quits (remember folks, the memory a program allocates for itself is freed up again when it quits).

We are talking sophisticated stuff here. Writing system software is extremely tricky stuff, and even for Apple who knows every little subtle nuance in the Macintosh, it is a tough thing to do right. That is why System 7 took so long and why Apple should be praised for System 7 - it works well, which is nothing short of a miracle. But I digress.

You get the idea, writing system software is not for the faint of heart. In any case, INITs take a portion of System Heap memory for themselves when the computer starts up. It is also then that they "hook" themselves into the system software. When your computer first starts up, the System Heap is a certain fixed size. However, during the start up process, the System Heap grows automagically to accommodate an INIT that needs more memory for itself.

For technoweenies, the mechanism that loads INITs at start up time and expands the System Heap as needed is called INIT31. There is a well known mechanism that any INIT writer worth his salt takes advantage of: 'sysz', or System Zone Expansion. This is a little parcel that all INIT writers should include in their products (it takes all of two minutes to put it in), because it tells the INIT31 mechanism how much memory the INIT needs to load. INIT31 grows the System Heap so that there is at least this much memory free, and then loads and runs the INIT. In this way, any well-written INIT will tell INIT31 how much memory it needs, get it, and be happy. All is well in INIT-land.

In a perfect world, our story would end here. But as I'm sure you suspect, there are a few twists. INITs have the power to affect the operation of your entire computer, and unfortunately they can also crash the whole thing too. INITs can run into several different snags regarding the System Heap, and I will go into them one by one so that you can understand what goes wrong and why.

One thing we should get straight now - if your machine crashes because of an INIT, a programmer out there somewhere is at fault. Count on it. There are well established rules for writing INITs, so the real problem is that not all programmers understand the rules. Information on how to write INITs properly is also hard to come by, and programmers are only human - we're doing our best but we make mistakes.