3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Stack allocation
</title>
5 <link rel=
"stylesheet" href=
"../../../../../../doc/src/boostbook.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.75.2">
7 <link rel=
"home" href=
"../../index.html" title=
"Chapter 1. Context">
8 <link rel=
"up" href=
"../econtext.html" title=
"Execution context">
9 <link rel=
"prev" href=
"../econtext.html" title=
"Execution context">
10 <link rel=
"next" href=
"stack/protected_fixedsize.html" title=
"Class protected_fixedsize">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../../../libs/libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"../econtext.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../econtext.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"stack/protected_fixedsize.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>
26 <div class=
"titlepage"><div><div><h3 class=
"title">
27 <a name=
"context.econtext.stack"></a><a class=
"link" href=
"stack.html" title=
"Stack allocation">Stack allocation
</a>
28 </h3></div></div></div>
30 <dt><span class=
"section"><a href=
"stack/protected_fixedsize.html">Class
31 <span class=
"emphasis"><em>protected_fixedsize
</em></span></a></span></dt>
32 <dt><span class=
"section"><a href=
"stack/fixedsize.html">Class
<span class=
"emphasis"><em>fixedsize
</em></span></a></span></dt>
33 <dt><span class=
"section"><a href=
"stack/segmented.html">Class
<span class=
"emphasis"><em>segmented
</em></span></a></span></dt>
34 <dt><span class=
"section"><a href=
"stack/stack_traits.html">Class
<span class=
"emphasis"><em>stack_traits
</em></span></a></span></dt>
35 <dt><span class=
"section"><a href=
"stack/stack_context.html">Class
<span class=
"emphasis"><em>stack_context
</em></span></a></span></dt>
38 The memory used by the stack is allocated/deallocated via a
<span class=
"emphasis"><em>StackAllocator
</em></span>
39 which is required to model a
<span class=
"emphasis"><em>stack-allocator concept
</em></span>.
42 <a name=
"context.econtext.stack.h0"></a>
43 <span><a name=
"context.econtext.stack._emphasis_stack_allocator_concept__emphasis_"></a></span><a class=
"link" href=
"stack.html#context.econtext.stack._emphasis_stack_allocator_concept__emphasis_"><span class=
"emphasis"><em>stack-allocator
44 concept
</em></span></a>
47 A
<span class=
"emphasis"><em>StackAllocator
</em></span> must satisfy the
<span class=
"emphasis"><em>stack-allocator
48 concept
</em></span> requirements shown in the following table, in which
<code class=
"computeroutput"><span class=
"identifier">a
</span></code> is an object of a
<span class=
"emphasis"><em>StackAllocator
</em></span>
49 type,
<code class=
"computeroutput"><span class=
"identifier">sctx
</span></code> is a
<code class=
"computeroutput"><span class=
"identifier">stack_context
</span></code>, and
<code class=
"computeroutput"><span class=
"identifier">size
</span></code>
50 is a
<code class=
"computeroutput"><span class=
"identifier">std
</span><span class=
"special">::
</span><span class=
"identifier">size_t
</span></code>:
52 <div class=
"informaltable"><table class=
"table">
79 <code class=
"computeroutput"><span class=
"identifier">a
</span><span class=
"special">(
</span><span class=
"identifier">size
</span><span class=
"special">)
</span></code>
86 creates a stack allocator
93 <code class=
"computeroutput"><span class=
"identifier">a
</span><span class=
"special">.
</span><span class=
"identifier">allocate
</span><span class=
"special">()
</span></code>
98 <code class=
"computeroutput"><span class=
"identifier">stack_context
</span></code>
110 <code class=
"computeroutput"><span class=
"identifier">a
</span><span class=
"special">.
</span><span class=
"identifier">deallocate
</span><span class=
"special">(
</span>
111 <span class=
"identifier">sctx
</span><span class=
"special">)
</span></code>
116 <code class=
"computeroutput"><span class=
"keyword">void
</span></code>
121 deallocates the stack created by
<code class=
"computeroutput"><span class=
"identifier">a
</span><span class=
"special">.
</span><span class=
"identifier">allocate
</span><span class=
"special">()
</span></code>
127 <div class=
"important"><table border=
"0" summary=
"Important">
129 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Important]" src=
"../../../../../../doc/src/images/important.png"></td>
130 <th align=
"left">Important
</th>
132 <tr><td align=
"left" valign=
"top"><p>
133 The implementation of
<code class=
"computeroutput"><span class=
"identifier">allocate
</span><span class=
"special">()
</span></code> might include logic to protect against
134 exceeding the context's available stack size rather than leaving it as
138 <div class=
"important"><table border=
"0" summary=
"Important">
140 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Important]" src=
"../../../../../../doc/src/images/important.png"></td>
141 <th align=
"left">Important
</th>
143 <tr><td align=
"left" valign=
"top"><p>
144 Calling
<code class=
"computeroutput"><span class=
"identifier">deallocate
</span><span class=
"special">()
</span></code>
145 with a
<code class=
"computeroutput"><span class=
"identifier">stack_context
</span></code> not
146 set by
<code class=
"computeroutput"><span class=
"identifier">allocate
</span><span class=
"special">()
</span></code>
147 results in undefined behaviour.
150 <div class=
"note"><table border=
"0" summary=
"Note">
152 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Note]" src=
"../../../../../../doc/src/images/note.png"></td>
153 <th align=
"left">Note
</th>
155 <tr><td align=
"left" valign=
"top"><p>
156 The stack is not required to be aligned; alignment takes place inside
157 <span class=
"emphasis"><em>execution_context
</em></span>.
160 <div class=
"note"><table border=
"0" summary=
"Note">
162 <td rowspan=
"2" align=
"center" valign=
"top" width=
"25"><img alt=
"[Note]" src=
"../../../../../../doc/src/images/note.png"></td>
163 <th align=
"left">Note
</th>
165 <tr><td align=
"left" valign=
"top"><p>
166 Depending on the architecture
<code class=
"computeroutput"><span class=
"identifier">allocate
</span><span class=
"special">()
</span></code> stores an address from the top of the
167 stack (growing downwards) or the bottom of the stack (growing upwards).
171 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
172 <td align=
"left"></td>
173 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2014 Oliver Kowalke
<p>
174 Distributed under the Boost Software License, Version
1.0. (See accompanying
175 file LICENSE_1_0.txt or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt" target=
"_top">http://www.boost.org/LICENSE_1_0.txt
</a>)
180 <div class=
"spirit-nav">
181 <a accesskey=
"p" href=
"../econtext.html"><img src=
"../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../econtext.html"><img src=
"../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../index.html"><img src=
"../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"stack/protected_fixedsize.html"><img src=
"../../../../../../doc/src/images/next.png" alt=
"Next"></a>