Specifications
Apple II Technical Notes
Apple IIGS
2 of 2 #78: Bank Alignment and Memory Management
cannot know themselves, since they are only told how much memory is needed, not where it has to
be. Therefore, whenever the Memory Manager returns error $0201, all purgeable handles have
been purged.
This is particularly annoying to loaders. OMF supports a “bank-aligned” attribute for load
segments, and the loaders ensure that such segments are loaded at the beginning of some bank or
another. The Memory Manager does not have a “bank-aligned” attribute for handles, so the
loaders have to do these things themselves. They do this by asking for a handle of the appropriate
size at the beginning of bank two. If this fails, the loaders try again with bank three, then bank four,
and so on through the end of memory.
Since some part of GS/OS is almost always occupying the memory at the beginning of bank two,
which is where the loader first attempts to load a bank-aligned segment, the presence of such a
segment in a load file virtually guarantees that all purgeable handles are purged when the file is
loaded. This kicks out dormant applications and zombie-state tool sets, among other things,
requiring they be loaded from disk again when needed.
Starting with System Software 6.0, the Loader attempts an alternate strategy first—it tries to allocate
an entire bank of memory that is page aligned and doesn’t cross a bank boundary. This block, if
available, will by definition be bank-aligned. Since code segments can’t be larger than 64K, such a
block can always hold a bank-aligned segment. The Loader now tries to allocate such a block and
if it finds one, it immediately disposes of it and allocates a block of the right size at the same bank
address.
If this strategy succeeds, it’s a lot faster than the other method and may avoid purging all of
memory. If it fails, though, the Memory Manager still goes through all seven steps before returning
error $0201, so all of memory may still be purged. It’s just less likely in System Software 6.0 and
later.
It doesn’t make sense to bank-align a small segment, and small segments fit better into fragmented
memory. If you use large segments anyway, consider the trade-off: bank-aligning a segment may
purge memory at load time, but your linker may be able to generate smaller OMF, decreasing disk
size and load time.
Summary
The general recommendation against asking for specific blocks of memory is well-known to most
developers; the reasons outlined above simply add fuel to the fire against such programming
practices. What isn’t as widely known is that having a bank-aligned load segment in a load file
may cause everything purgeable to be purged, and could also cause OOM queue routines to
dispose of handles when there really isn’t any kind of memory shortage.
Apple advises developers to carefully consider the advantages and disadvantages of bank-aligned
segments before including one in a load file.
Further Reference
• Apple IIGS Toolbox Reference, Volumes 1 and 3
• GS/OS Reference










