<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
region-based	B-General_Concept
memory	I-General_Concept
management	I-General_Concept
is	O
a	O
type	O
of	O
memory	B-General_Concept
management	I-General_Concept
in	O
which	O
each	O
allocated	O
object	O
is	O
assigned	O
to	O
a	O
region	O
.	O
</s>
<s>
A	O
region	O
,	O
also	O
called	O
a	O
zone	O
,	O
arena	B-General_Concept
,	O
area	O
,	O
or	O
memory	B-General_Concept
context	I-General_Concept
,	O
is	O
a	O
collection	O
of	O
allocated	O
objects	O
that	O
can	O
be	O
efficiently	O
reallocated	O
or	O
deallocated	O
all	O
at	O
once	O
.	O
</s>
<s>
Like	O
stack	B-General_Concept
allocation	I-General_Concept
,	O
regions	O
facilitate	O
allocation	O
and	O
deallocation	B-General_Concept
of	O
memory	O
with	O
low	O
overhead	O
;	O
but	O
they	O
are	O
more	O
flexible	O
,	O
allowing	O
objects	O
to	O
live	O
longer	O
than	O
the	O
stack	O
frame	O
in	O
which	O
they	O
were	O
allocated	O
.	O
</s>
<s>
As	O
a	O
simple	O
example	O
,	O
consider	O
the	O
following	O
C	B-Language
code	O
which	O
allocates	O
and	O
then	O
deallocates	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
data	O
structure	O
:	O
</s>
<s>
Although	O
it	O
required	O
many	O
operations	O
to	O
construct	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
it	O
can	O
be	O
quickly	O
deallocated	O
in	O
a	O
single	O
operation	O
by	O
destroying	O
the	O
region	O
in	O
which	O
the	O
nodes	O
were	O
allocated	O
.	O
</s>
<s>
Each	O
region	O
is	O
implemented	O
as	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
of	O
large	O
blocks	O
of	O
memory	O
;	O
each	O
block	O
should	O
be	O
large	O
enough	O
to	O
serve	O
many	O
allocations	O
.	O
</s>
<s>
Unlike	O
in	O
typical	O
garbage	B-General_Concept
collection	I-General_Concept
systems	O
,	O
there	O
is	O
no	O
need	O
to	O
tag	O
data	O
with	O
its	O
type	O
.	O
</s>
<s>
In	O
1976	O
,	O
the	O
PL/I	B-Language
standard	O
included	O
the	O
AREA	O
data	O
type	O
.	O
</s>
<s>
In	O
1990	O
,	O
Hanson	O
demonstrated	O
that	O
explicit	O
regions	O
in	O
C	B-Language
(	O
which	O
he	O
called	O
arenas	B-General_Concept
)	O
could	O
achieve	O
time	O
performance	O
per	O
allocated	O
byte	O
superior	O
to	O
even	O
the	O
fastest-known	O
heap	O
allocation	O
mechanism	O
.	O
</s>
<s>
Explicit	O
regions	O
were	O
instrumental	O
in	O
the	O
design	O
some	O
early	O
C-based	O
software	O
projects	O
,	O
including	O
the	O
Apache	B-Application
HTTP	I-Application
Server	I-Application
,	O
which	O
calls	O
them	O
pools	O
,	O
and	O
the	O
PostgreSQL	B-Application
database	O
management	O
system	O
,	O
which	O
calls	O
them	O
memory	B-General_Concept
contexts	I-General_Concept
.	O
</s>
<s>
Like	O
traditional	O
heap	O
allocation	O
,	O
these	O
schemes	O
do	O
not	O
provide	O
memory	B-Application
safety	I-Application
;	O
it	O
is	O
possible	O
for	O
a	O
programmer	O
to	O
access	O
a	O
region	O
after	O
it	O
is	O
deallocated	O
through	O
a	O
dangling	B-Error_Name
pointer	I-Error_Name
,	O
or	O
to	O
forget	O
to	O
deallocate	O
a	O
region	O
,	O
causing	O
a	O
memory	B-Error_Name
leak	I-Error_Name
.	O
</s>
<s>
In	O
1988	O
,	O
researchers	O
began	O
investigating	O
how	O
to	O
use	O
regions	O
for	O
safe	O
memory	B-General_Concept
allocation	I-General_Concept
by	O
introducing	O
the	O
concept	O
of	O
region	O
inference	O
,	O
where	O
the	O
creation	O
and	O
deallocation	B-General_Concept
of	O
regions	O
,	O
as	O
well	O
as	O
the	O
assignment	O
of	O
individual	O
static	O
allocation	O
expressions	O
to	O
particular	O
regions	O
,	O
is	O
inserted	O
by	O
the	O
compiler	O
at	O
compile-time	O
.	O
</s>
<s>
The	O
compiler	O
is	O
able	O
to	O
do	O
this	O
in	O
such	O
a	O
way	O
that	O
it	O
can	O
guarantee	O
dangling	B-Error_Name
pointers	I-Error_Name
and	O
leaks	O
do	O
not	O
occur	O
.	O
</s>
<s>
In	O
1994	O
,	O
this	O
work	O
was	O
generalized	O
in	O
a	O
seminal	O
work	O
by	O
Tofte	O
and	O
Talpin	O
to	O
support	O
type	B-Application
polymorphism	I-Application
and	O
higher-order	B-Language
functions	I-Language
in	O
Standard	B-Language
ML	I-Language
,	O
a	O
functional	B-Language
programming	I-Language
language	I-Language
,	O
using	O
a	O
different	O
algorithm	O
based	O
on	O
type	O
inference	O
and	O
the	O
theoretical	O
concepts	O
of	O
polymorphic	B-Application
region	O
types	O
and	O
the	O
region	O
calculus	O
.	O
</s>
<s>
Their	O
work	O
introduced	O
an	O
extension	O
of	O
the	O
lambda	B-Language
calculus	I-Language
including	O
regions	O
,	O
adding	O
two	O
constructs	O
:	O
</s>
<s>
This	O
extended	O
lambda	B-Language
calculus	I-Language
was	O
intended	O
to	O
serve	O
as	O
a	O
provably	O
memory-safe	B-Application
intermediate	B-Application
representation	I-Application
for	O
compiling	O
Standard	B-Language
ML	I-Language
programs	O
into	O
machine	O
code	O
,	O
but	O
building	O
a	O
translator	O
that	O
would	O
produce	O
good	O
results	O
on	O
large	O
programs	O
faced	O
a	O
number	O
of	O
practical	O
limitations	O
which	O
had	O
to	O
be	O
resolved	O
with	O
new	O
analyses	O
,	O
including	O
dealing	O
with	O
recursive	O
calls	O
,	O
tail	B-Language
calls	I-Language
,	O
and	O
eliminating	O
regions	O
which	O
contained	O
only	O
a	O
single	O
value	O
.	O
</s>
<s>
This	O
work	O
was	O
completed	O
in	O
1995	O
and	O
integrated	O
into	O
the	O
ML	O
Kit	O
,	O
a	O
version	O
of	O
ML	O
based	O
on	O
region	B-General_Concept
allocation	I-General_Concept
in	O
place	O
of	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
The	O
ML	O
Kit	O
was	O
eventually	O
scaled	O
to	O
large	O
applications	O
with	O
two	O
additions	O
:	O
a	O
scheme	O
for	O
separate	O
compilation	O
of	O
modules	O
,	O
and	O
a	O
hybrid	O
technique	O
combining	O
region	O
inference	O
with	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
Various	O
extensions	O
to	O
the	O
C	B-Language
programming	I-Language
language	I-Language
:	O
</s>
<s>
The	O
safe	O
C	B-Language
dialect	O
Cyclone	B-Language
,	O
which	O
among	O
many	O
other	O
features	O
adds	O
support	O
for	O
explicit	O
regions	O
,	O
and	O
evaluates	O
the	O
impact	O
of	O
migrating	O
existing	O
C	B-Language
applications	O
to	O
use	O
them	O
.	O
</s>
<s>
An	O
extension	O
to	O
C	B-Language
called	O
RC	O
was	O
implemented	O
that	O
uses	O
explicitly-managed	O
regions	O
,	O
but	O
also	O
uses	O
reference	B-General_Concept
counting	I-General_Concept
on	O
regions	O
to	O
guarantee	O
memory	B-Application
safety	I-Application
by	O
ensuring	O
that	O
no	O
region	O
is	O
freed	O
prematurely	O
.	O
</s>
<s>
Regions	O
decrease	O
the	O
overhead	O
of	O
reference	B-General_Concept
counting	I-General_Concept
,	O
since	O
references	O
internal	O
to	O
regions	O
do	O
n't	O
require	O
counts	O
to	O
be	O
updated	O
when	O
they	O
're	O
modified	O
.	O
</s>
<s>
RC	O
includes	O
an	O
explicit	O
static	O
type	O
system	O
for	O
regions	O
that	O
allows	O
some	O
reference	B-General_Concept
count	I-General_Concept
updates	O
to	O
be	O
eliminated	O
.	O
</s>
<s>
A	O
restriction	O
of	O
C	B-Language
called	O
Control-C	O
limits	O
programs	O
to	O
use	O
regions	O
(	O
and	O
only	O
a	O
single	O
region	O
at	O
a	O
time	O
)	O
,	O
as	O
part	O
of	O
its	O
design	O
to	O
statically	O
ensure	O
memory	B-Application
safety	I-Application
.	O
</s>
<s>
Regions	O
were	O
implemented	O
for	O
a	O
subset	O
of	O
Java	B-Language
,	O
and	O
became	O
a	O
critical	O
component	O
of	O
memory	B-General_Concept
management	I-General_Concept
in	O
Real	B-Language
time	I-Language
Java	I-Language
,	O
which	O
combines	O
them	O
with	O
ownership	O
types	O
to	O
demonstrate	O
object	O
encapsulation	O
and	O
eliminate	O
runtime	O
checks	O
on	O
region	O
deallocation	B-General_Concept
.	O
</s>
<s>
More	O
recently	O
,	O
a	O
semi-automatic	O
system	O
was	O
proposed	O
for	O
inferring	O
regions	O
in	O
embedded	O
real-time	B-Language
Java	I-Language
applications	O
,	O
combining	O
a	O
compile-time	O
static	O
analysis	O
,	O
a	O
runtime	O
region	B-General_Concept
allocation	I-General_Concept
policy	O
,	O
and	O
programmer	O
hints	O
.	O
</s>
<s>
Regions	O
are	O
a	O
good	O
fit	O
for	O
real-time	B-General_Concept
computing	I-General_Concept
because	O
their	O
time	O
overhead	O
is	O
statically	O
predictable	O
,	O
without	O
the	O
complexity	O
of	O
incremental	O
garbage	B-General_Concept
collection	I-General_Concept
.	O
</s>
<s>
They	O
were	O
implemented	O
for	O
the	O
logic	B-Language
programming	I-Language
languages	I-Language
Prolog	B-Language
and	O
Mercury	B-Operating_System
by	O
extending	O
Tofte	O
and	O
Talpin	O
's	O
region	O
inference	O
model	O
to	O
support	O
backtracking	O
and	O
cuts	O
.	O
</s>
<s>
Region-based	O
storage	O
management	O
is	O
used	O
throughout	O
the	O
parallel	O
programming	O
language	O
ParaSail	B-Application
.	O
</s>
<s>
Due	O
to	O
the	O
lack	O
of	O
explicit	O
pointers	O
in	O
ParaSail	B-Application
,	O
there	O
is	O
no	O
need	O
for	O
reference	B-General_Concept
counting	I-General_Concept
.	O
</s>
<s>
Debugging	O
this	O
type	O
of	O
problem	O
is	O
especially	O
difficult	O
in	O
systems	O
using	O
region	O
inference	O
,	O
where	O
the	O
programmer	O
must	O
understand	O
the	O
underlying	O
inference	O
algorithm	O
,	O
or	O
examine	O
the	O
verbose	O
intermediate	B-Application
representation	I-Application
,	O
to	O
diagnose	O
the	O
issue	O
.	O
</s>
<s>
Tracing	B-General_Concept
garbage	I-General_Concept
collectors	I-General_Concept
are	O
more	O
effective	O
at	O
deallocating	O
this	O
type	O
of	O
data	O
in	O
a	O
timely	O
manner	O
without	O
program	O
changes	O
;	O
this	O
was	O
one	O
justification	O
for	O
hybrid	O
region/GC	O
systems	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
tracing	B-General_Concept
garbage	I-General_Concept
collectors	I-General_Concept
can	O
also	O
exhibit	O
subtle	O
leaks	O
,	O
if	O
references	O
are	O
retained	O
to	O
data	O
which	O
will	O
never	O
be	O
used	O
again	O
.	O
</s>
<s>
Region-based	B-General_Concept
memory	I-General_Concept
management	I-General_Concept
works	O
best	O
when	O
the	O
number	O
of	O
regions	O
is	O
relatively	O
small	O
and	O
each	O
contains	O
many	O
objects	O
;	O
programs	O
that	O
contain	O
many	O
sparse	O
regions	O
will	O
exhibit	O
internal	O
fragmentation	O
,	O
leading	O
to	O
wasted	O
memory	O
and	O
a	O
time	O
overhead	O
for	O
region	O
management	O
.	O
</s>
<s>
As	O
mentioned	O
above	O
,	O
RC	O
uses	O
a	O
hybrid	O
of	O
regions	O
and	O
reference	B-General_Concept
counting	I-General_Concept
,	O
limiting	O
the	O
overhead	O
of	O
reference	B-General_Concept
counting	I-General_Concept
since	O
references	O
internal	O
to	O
regions	O
do	O
n't	O
require	O
counts	O
to	O
be	O
updated	O
when	O
they	O
're	O
modified	O
.	O
</s>
<s>
Similarly	O
,	O
some	O
mark-region	O
hybrid	O
methods	O
combine	O
tracing	B-General_Concept
garbage	I-General_Concept
collection	I-General_Concept
with	O
regions	O
;	O
these	O
function	O
by	O
dividing	O
the	O
heap	O
into	O
regions	O
,	O
performing	O
a	O
mark-sweep	O
pass	O
in	O
which	O
any	O
regions	O
containing	O
live	O
objects	O
are	O
marked	O
,	O
and	O
then	O
freeing	O
any	O
unmarked	O
regions	O
.	O
</s>
