1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Allocators</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-4-7.html">Previous</A> <A HREF="AA-4-9.html">Next</A></P>
<HR>
<H1> 4.8 Allocators</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [The evaluation of an <FONT FACE="Arial, Helvetica">allocator</FONT>
creates an object and yields an access value that designates the object.
<A NAME="I2831"></A><A NAME="I2832"></A><A NAME="I2833"></A>]</DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">allocator<A NAME="I2834"></A>
::= </FONT><BR>
<B>new</B> <A NAME="I2835"></A><FONT FACE="Arial, Helvetica">subtype_indication</FONT> | <B>new</B> <A NAME="I2836"></A><FONT FACE="Arial, Helvetica">qualified_expression</FONT></DIV>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>3/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0010">8652/0010</A></I>}
<A NAME="I2837"></A>The expected type for an <FONT FACE="Arial, Helvetica">allocator</FONT>
shall be a single access-to-object type <U>with</U><S>whose</S> designated
type <U><I>D</I> such that either <I>D</I></U> covers the type determined
by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT> of the <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
or <FONT FACE="Arial, Helvetica">qualified_expression</FONT><U>, or the
expected type is anonymous and the determined type is <I>D</I>'Class</U>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>See <A HREF="AA-8-6.html">8.6</A>,
``<A HREF="AA-8-6.html">The Context of Overload Resolution</A>'' for
the meaning of ``shall be a single ... type whose ...'' </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a.1/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>{<I><A HREF="defect1.html#8652/0010">8652/0010</A></I>}
<U>An allocator is allowed as a controlling parameter of a dispatching
call (see <A HREF="AA-3-9-2.html">3.9.2</A>).</U> </FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2838"></A>An <I>initialized</I> allocator
is an <FONT FACE="Arial, Helvetica">allocator</FONT> with a <FONT FACE="Arial, Helvetica">qualified_expression</FONT>.
<A NAME="I2839"></A>An <I>uninitialized</I> allocator is one with a <FONT FACE="Arial, Helvetica">subtype_indication</FONT>.
In the <FONT FACE="Arial, Helvetica">subtype_indication</FONT> of an
uninitialized allocator, a <FONT FACE="Arial, Helvetica">constraint</FONT>
is permitted only if the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
denotes an [unconstrained] composite subtype; if there is no <FONT FACE="Arial, Helvetica">constraint</FONT>,
then the <FONT FACE="Arial, Helvetica">subtype_mark</FONT> shall denote
a definite subtype. <A NAME="I2840"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For example,
... <B>new</B> S'Class ... (with no initialization expression) is illegal,
but ... <B>new</B> S'Class'(X) ... is legal, and takes its tag and constraints
from the initial value X. (Note that the former case cannot have a constraint.)
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal"> If the type of the <FONT FACE="Arial, Helvetica">allocator</FONT>
is an access-to-constant type, the <FONT FACE="Arial, Helvetica">allocator</FONT>
shall be an initialized allocator. If the designated type is limited,
the <FONT FACE="Arial, Helvetica">allocator</FONT> shall be an uninitialized
allocator. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>For an access-to-constant
type whose designated type is limited, <FONT FACE="Arial, Helvetica">allocator</FONT>s
are illegal. The Access attribute is legal for such a type, however.
</FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> If the designated type of the type of the <FONT FACE="Arial, Helvetica">allocator</FONT>
is elementary, then the subtype of the created object is the designated
subtype. If the designated type is composite, then the created object
is always constrained; if the designated subtype is constrained, then
it provides the constraint of the created object; otherwise, the object
is constrained by its initial value [(even if the designated subtype
is unconstrained with defaults)]. <A NAME="I2841"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>See AI83-00331.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>All objects created
by an allocator are aliased, and all aliased composite objects need to
be constrained so that access subtypes work reasonably. </FONT></DIV>
<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2842"></A>For the evaluation of an <FONT FACE="Arial, Helvetica">allocator</FONT>,
the elaboration of the <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
or the evaluation of the <FONT FACE="Arial, Helvetica">qualified_expression</FONT>
is performed first. <A NAME="I2843"></A><A NAME="I2844"></A>For the evaluation
of an initialized allocator, an object of the designated type is created
and the value of the <FONT FACE="Arial, Helvetica">qualified_expression</FONT>
is converted to the designated subtype and assigned to the object. <A NAME="I2845"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The conversion
might raise Constraint_Error. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2846"></A>For the evaluation of an uninitialized
allocator: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC><A NAME="I2847"></A>If the designated type is elementary,
an object of the designated subtype is created and any implicit initial
value is assigned;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10/1</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>{<I><A HREF="defect1.html#8652/0002">8652/0002</A></I>}
<A NAME="I2848"></A>If the designated type is composite, an object of
the designated type is created with tag, if any, determined by the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
of the <FONT FACE="Arial, Helvetica">subtype_indication</FONT>; any per-object
constraints on subcomponents are elaborated <U>(see <A HREF="AA-3-8.html">3.8</A>)
</U>and any implicit initial values for the subcomponents of the object
are obtained as determined by the <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
and assigned to the corresponding subcomponents. <A NAME="I2849"></A><A NAME="I2850"></A><A NAME="I2851"></A><A NAME="I2852"></A>A
check is made that the value of the object belongs to the designated
subtype. <A NAME="I2853"></A>Constraint_Error is raised if this check
fails. This check and the initialization of the object are performed
in an arbitrary order. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>AI83-00150.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> [If the created object contains any tasks, they
are activated (see <A HREF="AA-9-2.html">9.2</A>).] Finally, an access
value that designates the created object is returned. </DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>24 Allocators cannot create
objects of an abstract type. See <A HREF="AA-3-9-3.html">3.9.3</A>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>25 If any part of the created
object is controlled, the initialization includes calls on corresponding
Initialize or Adjust procedures. See <A HREF="AA-7-6.html">7.6</A>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>26 As explained in <A HREF="AA-13-11.html">13.11</A>,
``<A HREF="AA-13-11.html">Storage Management</A>'', the storage for an
object allocated by an <FONT FACE="Arial, Helvetica">allocator</FONT>
comes from a storage pool (possibly user defined). <A NAME="I2854"></A>The
exception Storage_Error is raised by an <FONT FACE="Arial, Helvetica">allocator</FONT>
if there is not enough storage. Instances of Unchecked_Deallocation may
be used to explicitly reclaim storage.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>27 Implementations are permitted,
but not required, to provide garbage collection (see <A HREF="AA-13-11-3.html">13.11.3</A>).
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Note that
in an <FONT FACE="Arial, Helvetica">allocator</FONT>, the exception Constraint_Error
can be raised by the evaluation of the <FONT FACE="Arial, Helvetica">qualified_expression</FONT>,
by the elaboration of the <FONT FACE="Arial, Helvetica">subtype_indication</FONT>,
or by the initialization. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>By default,
the implementation provides the storage pool. The user may exercise more
control over storage management by associating a user-defined pool with
an access type. </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
allocators:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Examples"><TT><B>new</B> Cell'(0, <B>null</B>, <B>null</B>) <I>-- initialized explicitly, see <A HREF="AA-3-10-1.html">3.10.1</A></I><BR>
<B>new</B> Cell'(Value => 0, Succ => <B>null</B>, Pred => <B>null</B>) <I>-- initialized explicitly</I><BR>
<B>new</B> Cell <I>-- not initialized</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Examples"><TT><B>new</B> Matrix(1 .. 10, 1 .. 20) <I>-- the bounds only are given</I><BR>
<B>new</B> Matrix'(1 .. 10 => (1 .. 20 => 0.0)) <I>-- initialized explicitly</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Examples"><TT><B>new</B> Buffer(100) <I>-- the discriminant only is given</I><BR>
<B>new</B> Buffer'(Size => 80, Pos => 0, Value => (1 .. 80 => 'A')) <I>-- initialized explicitly</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Examples"><TT>Expr_Ptr'(<B>new</B> Literal) <I>-- allocator for access-to-class-wide type, see <A HREF="AA-3-9-1.html">3.9.1</A></I><BR>
Expr_Ptr'(<B>new</B> Literal'(Expression <B>with</B> 3.5)) <I>-- initialized explicitly</I></TT></DIV>
<H4 ALIGN=CENTER>Incompatibilities With Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>20.a/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2855"></A>The <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
of an uninitialized allocator may not have an explicit <FONT FACE="Arial, Helvetica">constraint</FONT>
if the designated type is an access type. In Ada 83, this was permitted
even though the <FONT FACE="Arial, Helvetica">constraint</FONT> had no
<U>e</U><S>a</S>ffect on the subtype of the created object. </FONT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>20.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2856"></A>Allocators
creating objects of type <I>T</I> are now overloaded on access types
designating <I>T'</I>Class and all class-wide types that cover <I>T</I>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Implicit array subtype conversion
(sliding) is now performed as part of an initialized allocator. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>20.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We have used a new organization,
inspired by the ACID document, that makes it clearer what is the subtype
of the created object, and what subtype conversions take place.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Discussion of storage management
issues, such as garbage collection and the raising of Storage_Error,
has been moved to <A HREF="AA-13-11.html">13.11</A>, ``<A HREF="AA-13-11.html">Storage
Management</A>''. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-4-7.html">Previous</A> <A HREF="AA-4-9.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|