<s>
Historically	O
,	O
the	O
classic	B-Application
Mac	I-Application
OS	I-Application
used	O
a	O
form	O
of	O
memory	B-General_Concept
management	I-General_Concept
that	O
has	O
fallen	O
out	O
of	O
favor	O
in	O
modern	O
systems	O
.	O
</s>
<s>
The	O
original	O
problem	O
for	O
the	O
engineers	O
of	O
the	O
Macintosh	B-Device
was	O
how	O
to	O
make	O
optimum	O
use	O
of	O
the	O
128KB	O
of	O
RAM	B-Architecture
with	O
which	O
the	O
machine	O
was	O
equipped	O
,	O
on	O
Motorola	O
68000-based	O
computer	O
hardware	O
that	O
did	O
not	O
support	O
virtual	B-Architecture
memory	I-Architecture
.	O
</s>
<s>
Since	O
at	O
that	O
time	O
the	O
machine	O
could	O
only	O
run	O
one	O
application	B-Application
program	I-Application
at	O
a	O
time	O
,	O
and	O
there	O
was	O
no	O
fixed	B-Device
secondary	O
storage	O
,	O
the	O
engineers	O
implemented	O
a	O
simple	O
scheme	O
which	O
worked	O
well	O
with	O
those	O
particular	O
constraints	O
.	O
</s>
<s>
The	O
primary	O
concern	O
of	O
the	O
original	O
engineers	O
appears	O
to	O
have	O
been	O
fragmentation	B-Architecture
–	O
that	O
is	O
,	O
the	O
repeated	O
allocation	O
and	O
deallocation	B-General_Concept
of	O
memory	O
through	O
pointers	O
leading	O
to	O
many	O
small	O
isolated	O
areas	O
of	O
memory	O
which	O
cannot	O
be	O
used	O
because	O
they	O
are	O
too	O
small	O
,	O
even	O
though	O
the	O
total	O
free	O
memory	O
may	O
be	O
sufficient	O
to	O
satisfy	O
a	O
particular	O
request	O
for	O
memory	O
.	O
</s>
<s>
The	O
machine	O
itself	O
implemented	O
two	O
areas	O
in	O
memory	O
available	O
for	O
this	O
scheme	O
–	O
the	O
system	O
heap	O
(	O
used	O
for	O
the	O
OS	O
)	O
,	O
and	O
the	O
application	B-Application
heap	O
.	O
</s>
<s>
As	O
long	O
as	O
only	O
one	O
application	B-Application
at	O
a	O
time	O
was	O
run	O
,	O
the	O
system	O
worked	O
well	O
.	O
</s>
<s>
Since	O
the	O
entire	O
application	B-Application
heap	O
was	O
dissolved	O
when	O
the	O
application	B-Application
quit	O
,	O
fragmentation	B-Architecture
was	O
minimized	O
.	O
</s>
<s>
The	O
memory	B-General_Concept
management	I-General_Concept
system	O
had	O
weaknesses	O
;	O
the	O
system	O
heap	O
was	O
not	O
protected	O
from	O
errant	O
applications	O
,	O
as	O
would	O
have	O
been	O
possible	O
if	O
the	O
system	O
architecture	O
had	O
supported	O
memory	B-General_Concept
protection	I-General_Concept
,	O
and	O
this	O
was	O
frequently	O
the	O
cause	O
of	O
system	O
problems	O
and	O
crashes	B-General_Concept
.	O
</s>
<s>
This	O
was	O
a	O
real	O
problem	O
for	O
almost	O
every	O
system	O
API	B-Application
that	O
existed	O
.	O
</s>
<s>
Because	O
of	O
the	O
transparency	O
of	O
system-owned	O
data	O
structures	O
at	O
the	O
time	O
,	O
the	O
APIs	B-Application
could	O
do	O
little	O
to	O
solve	O
this	O
.	O
</s>
<s>
Thus	O
the	O
onus	O
was	O
on	O
the	O
programmer	O
not	O
to	O
create	O
such	O
pointers	O
,	O
or	O
at	O
least	O
manage	O
them	O
very	O
carefully	O
by	O
dereferencing	O
all	O
handles	O
after	O
every	O
such	O
API	B-Application
call	O
.	O
</s>
<s>
Since	O
many	O
programmers	O
were	O
not	O
generally	O
familiar	O
with	O
this	O
approach	O
,	O
early	O
Mac	B-Device
programs	O
suffered	O
frequently	O
from	O
faults	O
arising	O
from	O
this	O
.	O
</s>
<s>
Palm	B-Operating_System
OS	I-Operating_System
and	O
16-bit	O
Windows	O
use	O
a	O
similar	O
scheme	O
for	O
memory	B-General_Concept
management	I-General_Concept
,	O
but	O
the	O
Palm	O
and	O
Windows	O
versions	O
make	O
programmer	O
error	O
more	O
difficult	O
.	O
</s>
<s>
For	O
instance	O
,	O
in	O
Mac	B-Application
OS	I-Application
,	O
to	O
convert	O
a	O
handle	O
to	O
a	O
pointer	O
,	O
a	O
program	O
just	O
de-references	O
the	O
handle	O
directly	O
,	O
but	O
if	O
the	O
handle	O
is	O
not	O
locked	O
,	O
the	O
pointer	O
can	O
become	O
invalid	O
quickly	O
.	O
</s>
<s>
In	O
Palm	B-Operating_System
OS	I-Operating_System
and	O
Windows	O
,	O
handles	O
are	O
an	O
opaque	O
type	O
and	O
must	O
be	O
de-referenced	O
with	O
on	O
Palm	B-Operating_System
OS	I-Operating_System
or	O
on	O
Windows	O
.	O
</s>
<s>
When	O
a	O
Palm	O
or	O
Windows	O
application	B-Application
is	O
finished	O
with	O
a	O
handle	O
,	O
it	O
calls	O
or	O
.	O
</s>
<s>
Palm	B-Operating_System
OS	I-Operating_System
and	O
Windows	O
keep	O
a	O
lock	O
count	O
for	O
blocks	O
;	O
after	O
three	O
calls	O
to	O
,	O
a	O
block	O
will	O
only	O
become	O
unlocked	O
after	O
three	O
calls	O
to	O
.	O
</s>
<s>
The	O
situation	O
worsened	O
with	O
the	O
advent	O
of	O
Switcher	O
,	O
which	O
was	O
a	O
way	O
for	O
a	O
Mac	B-Device
with	O
512KB	O
or	O
more	O
of	O
memory	O
to	O
run	O
multiple	O
applications	O
at	O
once	O
.	O
</s>
<s>
Because	O
Apple	O
was	O
now	O
committed	O
to	O
its	O
memory	B-General_Concept
management	I-General_Concept
model	O
,	O
as	O
well	O
as	O
compatibility	O
with	O
existing	O
applications	O
,	O
it	O
was	O
forced	O
to	O
adopt	O
a	O
scheme	O
where	O
each	O
application	B-Application
was	O
allocated	O
its	O
own	O
heap	O
from	O
the	O
available	O
RAM	B-Architecture
.	O
</s>
<s>
The	O
amount	O
of	O
actual	O
RAM	B-Architecture
allocated	O
to	O
each	O
heap	O
was	O
set	O
by	O
a	O
value	O
coded	O
into	O
the	O
metadata	O
of	O
each	O
application	B-Application
,	O
set	O
by	O
the	O
programmer	O
.	O
</s>
<s>
While	O
popular	O
among	O
"	O
power	B-General_Concept
users	I-General_Concept
"	O
,	O
this	O
exposure	O
of	O
a	O
technical	O
implementation	O
detail	O
was	O
against	O
the	O
grain	O
of	O
the	O
Mac	B-Device
user	O
philosophy	O
.	O
</s>
<s>
Apart	O
from	O
exposing	O
users	O
to	O
esoteric	O
technicalities	O
,	O
it	O
was	O
inefficient	O
,	O
since	O
an	O
application	B-Application
would	O
be	O
made	O
to	O
grab	O
all	O
of	O
its	O
allotted	O
RAM	B-Architecture
,	O
even	O
if	O
it	O
left	O
most	O
of	O
it	O
subsequently	O
unused	O
.	O
</s>
<s>
Another	O
application	B-Application
might	O
be	O
memory	O
starved	O
,	O
but	O
would	O
be	O
unable	O
to	O
utilize	O
the	O
free	O
memory	O
"	O
owned	O
"	O
by	O
another	O
application	B-Application
.	O
</s>
<s>
While	O
an	O
application	B-Application
could	O
not	O
beneficially	O
utilize	O
a	O
sister	O
application	B-Application
's	O
heap	O
,	O
it	O
could	O
certainly	O
destroy	O
it	O
,	O
typically	O
by	O
inadvertently	O
writing	O
to	O
a	O
nonsense	O
address	O
.	O
</s>
<s>
An	O
application	B-Application
accidentally	O
treating	O
a	O
fragment	O
of	O
text	O
or	O
image	O
,	O
or	O
an	O
unassigned	O
location	O
as	O
a	O
pointer	O
could	O
easily	O
overwrite	O
the	O
code	O
or	O
data	O
of	O
other	O
applications	O
or	O
even	O
the	O
OS	O
,	O
leaving	O
"	O
lurkers	O
"	O
even	O
after	O
the	O
program	O
was	O
exited	O
.	O
</s>
<s>
Switcher	O
evolved	O
into	O
MultiFinder	O
in	O
System	O
4.2	O
,	O
which	O
became	O
the	O
Process	O
Manager	O
in	O
System	B-Operating_System
7	I-Operating_System
,	O
and	O
by	O
then	O
the	O
scheme	O
was	O
long	O
entrenched	O
.	O
</s>
<s>
Apple	O
made	O
some	O
attempts	O
to	O
work	O
around	O
the	O
obvious	O
limitations	O
–	O
temporary	O
memory	O
was	O
one	O
,	O
where	O
an	O
application	B-Application
could	O
"	O
borrow	O
"	O
free	O
RAM	B-Architecture
that	O
lay	O
outside	O
of	O
its	O
heap	O
for	O
short	O
periods	O
,	O
but	O
this	O
was	O
unpopular	O
with	O
programmers	O
so	O
it	O
largely	O
failed	O
to	O
solve	O
the	O
problems	O
.	O
</s>
<s>
Apple	O
's	O
System	B-Operating_System
7	I-Operating_System
Tune-up	O
addon	O
added	O
a	O
"	O
minimum	O
"	O
memory	O
size	O
and	O
a	O
"	O
preferred	O
"	O
sizeif	O
the	O
preferred	O
amount	O
of	O
memory	O
was	O
not	O
available	O
,	O
the	O
program	O
could	O
launch	O
in	O
the	O
minimum	O
space	O
,	O
possibly	O
with	O
reduced	O
functionality	O
.	O
</s>
<s>
Virtual	B-Architecture
memory	I-Architecture
schemes	O
,	O
which	O
made	O
more	O
memory	O
available	O
by	O
paging	O
unused	O
portions	O
of	O
memory	O
to	O
disk	O
,	O
were	O
made	O
available	O
by	O
third-party	O
utilities	O
like	O
Connectix	O
Virtual	O
,	O
and	O
then	O
by	O
Apple	O
in	O
System	B-Operating_System
7	I-Operating_System
.	O
</s>
<s>
This	O
increased	O
Macintosh	B-Device
memory	O
capacity	O
at	O
a	O
performance	O
cost	O
,	O
but	O
did	O
not	O
add	O
protected	B-General_Concept
memory	I-General_Concept
or	O
prevent	O
the	O
memory	O
manager	O
's	O
heap	B-General_Concept
compaction	I-General_Concept
that	O
would	O
invalidate	O
some	O
pointers	O
.	O
</s>
<s>
Originally	O
the	O
Macintosh	B-Device
had	O
128KB	O
of	O
RAM	B-Architecture
,	O
with	O
a	O
true	O
limit	O
of	O
4MB	O
,	O
despite	O
being	O
soldered	O
.	O
</s>
<s>
This	O
limit	O
would	O
first	O
be	O
reached	O
with	O
the	O
Macintosh	B-Device
Plus	I-Device
and	O
its	O
user	O
upgradable	O
memory	O
.	O
</s>
<s>
These	O
first	O
few	O
Macintosh	B-Device
computers	I-Device
used	O
the	O
68000	B-Device
CPU	O
,	O
a	O
32-bit	O
processor	O
,	O
but	O
only	O
had	O
24	O
physical	O
address	O
lines	O
.	O
</s>
<s>
The	O
RAM	B-Architecture
limit	O
in	O
the	O
Macintosh	B-Device
design	O
was	O
4MB	O
of	O
RAM	B-Architecture
and	O
4MB	O
of	O
ROM	B-Device
with	O
the	O
remaining	O
8MB	O
addresses	O
split	O
between	O
the	O
SCC	B-Device
,	I-Device
IWM	I-Device
and	I-Device
VIA	I-Device
chips	I-Device
,	O
because	O
of	O
the	O
structure	O
of	O
the	O
memory	O
map	O
.	O
</s>
<s>
This	O
was	O
fixed	B-Device
by	O
changing	O
the	O
memory	O
map	O
with	O
the	O
Macintosh	B-Device
II	I-Device
,	O
allowing	O
up	O
to	O
8MB	O
of	O
RAM	B-Architecture
,	O
by	O
shrinking	O
ROM	B-Device
and	O
I/O	O
addresses	O
to	O
1MB	O
each	O
and	O
allocating	O
the	O
remaining	O
6MB	O
addresses	O
to	O
the	O
NuBus	B-Device
slots	O
.	O
</s>
<s>
Connectix	O
products	O
MAXIMA	O
,	O
RAM	B-Architecture
Doubler	O
,	O
and	O
Virtual	O
allowed	O
accessing	O
and	O
reallocating	O
the	O
6MB	O
addresses	O
allocated	O
to	O
the	O
NuBus	B-Device
cards	O
for	O
a	O
total	O
of	O
14MB	O
,	O
minus	O
1MB	O
per	O
slot	O
occupied	O
.	O
</s>
<s>
Because	O
memory	O
was	O
a	O
scarce	O
resource	O
,	O
the	O
authors	O
of	O
Mac	B-Application
OS	I-Application
decided	O
to	O
take	O
advantage	O
of	O
the	O
unused	O
byte	O
in	O
each	O
address	O
.	O
</s>
<s>
The	O
original	O
Memory	O
Manager	O
(	O
up	O
until	O
the	O
advent	O
of	O
System	B-Operating_System
7	I-Operating_System
)	O
placed	O
flags	O
in	O
the	O
high	O
8bits	O
of	O
each	O
32-bit	O
pointer	O
and	O
handle	O
.	O
</s>
<s>
While	O
a	O
good	O
use	O
of	O
very	O
limited	O
RAM	B-Architecture
space	O
,	O
this	O
design	O
caused	O
problems	O
when	O
Apple	O
introduced	O
the	O
Macintosh	B-Device
II	I-Device
,	O
which	O
used	O
the	O
32-bit	O
Motorola	B-Device
68020	I-Device
CPU	O
.	O
</s>
<s>
The	O
68020	B-Device
had	O
32	O
physical	O
address	O
lines	O
which	O
could	O
address	O
up	O
to	O
4GB	O
of	O
memory	O
.	O
</s>
<s>
On	O
the	O
Macintosh	B-Device
IIci	I-Device
and	O
later	O
machines	O
,	O
and	O
other	O
APIs	B-Application
were	O
rewritten	O
to	O
implement	O
handle	O
locking	O
in	O
a	O
way	O
other	O
than	O
flagging	O
the	O
high	O
bits	O
of	O
handles	O
.	O
</s>
<s>
But	O
many	O
Macintosh	B-Device
application	B-Application
programmers	O
and	O
a	O
great	O
deal	O
of	O
the	O
Macintosh	B-Application
system	I-Application
software	I-Application
code	O
itself	O
accessed	O
the	O
flags	O
directly	O
rather	O
than	O
using	O
the	O
APIs	B-Application
,	O
such	O
as	O
,	O
which	O
had	O
been	O
provided	O
to	O
manipulate	O
them	O
.	O
</s>
<s>
In	O
order	O
to	O
stop	O
continual	O
system	B-General_Concept
crashes	I-General_Concept
caused	O
by	O
this	O
issue	O
,	O
System	O
6	O
and	O
earlier	O
running	O
on	O
a	O
68020	B-Device
or	O
a	O
68030	O
would	O
force	O
the	O
machine	O
into	O
24-bit	O
mode	O
,	O
and	O
would	O
only	O
recognize	O
and	O
address	O
the	O
first	O
8	O
megabytes	O
of	O
RAM	B-Architecture
,	O
an	O
obvious	O
flaw	O
in	O
machines	O
whose	O
hardware	O
was	O
wired	O
to	O
accept	O
up	O
to	O
128MB	O
RAM	B-Architecture
–	O
and	O
whose	O
product	O
literature	O
advertised	O
this	O
capability	O
.	O
</s>
<s>
With	O
System	B-Operating_System
7	I-Operating_System
,	O
the	O
Mac	B-Device
system	B-Application
software	I-Application
was	O
finally	O
made	O
32-bit	O
clean	O
,	O
but	O
there	O
were	O
still	O
the	O
problem	O
of	O
dirty	O
ROMs	O
.	O
</s>
<s>
The	O
problem	O
was	O
that	O
the	O
decision	O
to	O
use	O
24-bit	O
or	O
32-bit	O
addressing	O
has	O
to	O
be	O
made	O
very	O
early	O
in	O
the	O
boot	O
process	O
,	O
when	O
the	O
ROM	B-Device
routines	O
initialized	O
the	O
Memory	O
Manager	O
to	O
set	O
up	O
a	O
basic	O
Mac	B-Device
environment	O
where	O
NuBus	B-Device
ROMs	O
and	O
disk	O
drivers	O
are	O
loaded	O
and	O
executed	O
.	O
</s>
<s>
Surprisingly	O
,	O
the	O
first	O
solution	O
to	O
this	O
flaw	O
was	O
published	O
by	O
software	O
utility	O
company	O
Connectix	O
,	O
whose	O
System	O
6	O
extension	O
,	O
OPTIMA	O
,	O
reinitialized	O
the	O
Memory	O
Manager	O
and	O
repeated	O
early	O
parts	O
of	O
the	O
Mac	B-Device
boot	O
process	O
,	O
allowing	O
the	O
system	O
to	O
boot	O
into	O
32-bit	O
mode	O
and	O
enabling	O
the	O
use	O
of	O
all	O
the	O
RAM	B-Architecture
in	O
the	O
machine	O
.	O
</s>
<s>
OPTIMA	O
would	O
later	O
evolve	O
into	O
the	O
more	O
familiar	O
1991	O
product	O
,	O
MODE32	B-Application
,	O
for	O
System	B-Operating_System
7	I-Operating_System
.	O
</s>
<s>
The	O
Macintosh	B-Device
IIci	I-Device
and	O
later	O
Motorola	O
based	O
Macintosh	B-Device
computers	I-Device
had	O
32-bit	O
clean	O
ROMs	O
.	O
</s>
<s>
It	O
was	O
quite	O
a	O
while	O
before	O
applications	O
were	O
updated	O
to	O
remove	O
all	O
24-bit	O
dependencies	O
,	O
and	O
System	B-Operating_System
7	I-Operating_System
provided	O
a	O
way	O
to	O
switch	O
back	O
to	O
24-bit	O
mode	O
if	O
application	B-Application
incompatibilities	O
were	O
found	O
.	O
</s>
<s>
By	O
the	O
time	O
of	O
migration	O
to	O
the	O
PowerPC	O
and	O
System	B-Operating_System
7.1.2	I-Operating_System
,	O
32-bit	O
cleanliness	O
was	O
mandatory	O
for	O
creating	O
native	O
applications	O
and	O
even	O
later	O
Motorola	B-Device
68040	I-Device
based	O
Macs	B-Device
could	O
not	O
support	O
24-bit	O
mode	O
.	O
</s>
<s>
The	O
rise	O
of	O
object-oriented	B-Language
languages	I-Language
for	O
programming	O
the	O
Mac	B-Device
–	O
first	O
Object	B-Language
Pascal	I-Language
,	O
then	O
later	O
C++	B-Language
–	O
also	O
caused	O
problems	O
for	O
the	O
memory	O
model	O
adopted	O
.	O
</s>
<s>
These	O
languages	O
,	O
as	O
they	O
were	O
originally	O
designed	O
,	O
used	O
pointers	O
for	O
objects	O
,	O
which	O
would	O
lead	O
to	O
fragmentation	B-Architecture
issues	O
.	O
</s>
<s>
A	O
solution	O
,	O
implemented	O
by	O
the	O
THINK	B-Operating_System
(	O
later	O
Symantec	O
)	O
compilers	B-Language
,	O
was	O
to	O
use	O
Handles	O
internally	O
for	O
objects	O
,	O
but	O
use	O
a	O
pointer	O
syntax	O
to	O
access	O
them	O
.	O
</s>
<s>
This	O
seemed	O
a	O
good	O
idea	O
at	O
first	O
,	O
but	O
soon	O
deep	O
problems	O
emerged	O
,	O
since	O
programmers	O
could	O
not	O
tell	O
whether	O
they	O
were	O
dealing	O
with	O
a	O
relocatable	O
or	O
fixed	B-Device
block	O
,	O
and	O
so	O
had	O
no	O
way	O
to	O
know	O
whether	O
to	O
take	O
on	O
the	O
task	O
of	O
locking	O
objects	O
or	O
not	O
.	O
</s>
<s>
Later	O
compilers	B-Language
did	O
not	O
attempt	O
to	O
do	O
this	O
,	O
but	O
used	O
real	O
pointers	O
,	O
often	O
implementing	O
their	O
own	O
memory	B-General_Concept
allocation	I-General_Concept
schemes	O
to	O
work	O
around	O
the	O
Mac	B-Application
OS	I-Application
memory	O
model	O
.	O
</s>
<s>
While	O
the	O
Mac	B-Application
OS	I-Application
memory	O
model	O
,	O
with	O
all	O
its	O
inherent	O
problems	O
,	O
remained	O
this	O
way	O
right	O
through	O
to	O
Mac	B-Operating_System
OS	I-Operating_System
9	I-Operating_System
,	O
due	O
to	O
severe	O
application	B-Application
compatibility	O
constraints	O
,	O
the	O
increasing	O
availability	O
of	O
cheap	O
RAM	B-Architecture
meant	O
that	O
by	O
and	O
large	O
most	O
users	O
could	O
upgrade	O
their	O
way	O
out	O
of	O
a	O
corner	O
.	O
</s>
<s>
finally	O
did	O
away	O
with	O
the	O
whole	O
scheme	O
,	O
implementing	O
a	O
modern	O
paged	O
virtual	B-Architecture
memory	I-Architecture
scheme	O
.	O
</s>
<s>
A	O
subset	O
of	O
the	O
older	O
memory	O
model	O
APIs	B-Application
still	O
exists	O
for	O
compatibility	O
as	O
part	O
of	O
Carbon	B-Operating_System
,	O
but	O
maps	O
to	O
the	O
modern	O
memory	O
manager	O
(	O
a	O
thread-safe	O
implementation	O
)	O
underneath	O
.	O
</s>
