• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Class segmented_stack</title>
5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Context">
8<link rel="up" href="../stack.html" title="Stack allocation">
9<link rel="prev" href="fixedsize.html" title="Class fixedsize_stack">
10<link rel="next" href="stack_traits.html" title="Class stack_traits">
11</head>
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>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="fixedsize.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.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_traits.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<a name="context.stack.segmented"></a><a name="segmented"></a><a class="link" href="segmented.html" title="Class segmented_stack">Class
28      <span class="emphasis"><em>segmented_stack</em></span></a>
29</h3></div></div></div>
30<p>
31        <span class="bold"><strong>Boost.Context</strong></span> supports usage of a <a class="link" href="segmented.html#segmented"><span class="emphasis"><em>segmented_stack</em></span></a>, e. g. the
32        size of the stack grows on demand. The coroutine is created with a minimal
33        stack size and will be increased as required. Class <a class="link" href="segmented.html#segmented"><span class="emphasis"><em>segmented_stack</em></span></a>
34        models the <span class="emphasis"><em>stack-allocator concept</em></span>. In contrast to
35        <span class="emphasis"><em>protected_fixedsize_stack</em></span> and <span class="emphasis"><em>fixedsize_stack</em></span>
36        it creates a stack which grows on demand.
37      </p>
38<div class="note"><table border="0" summary="Note">
39<tr>
40<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
41<th align="left">Note</th>
42</tr>
43<tr><td align="left" valign="top"><p>
44          Segmented stacks are currently only supported by <span class="bold"><strong>gcc</strong></span>
45          from version <span class="bold"><strong>4.7</strong></span> <span class="bold"><strong>clang</strong></span>
46          from version <span class="bold"><strong>3.4</strong></span> onwards. In order to
47          use a <span class="emphasis"><em>segmented_stack</em></span> <span class="bold"><strong>Boost.Context</strong></span>
48          must be built with property <code class="computeroutput"><span class="identifier">segmented</span><span class="special">-</span><span class="identifier">stacks</span></code>,
49          e.g. <span class="bold"><strong>toolset=gcc segmented-stacks=on</strong></span> and
50          applying <code class="computeroutput"><span class="identifier">BOOST_USE_SEGMENTED_STACKS</span></code>
51          at b2/bjam command line.
52        </p></td></tr>
53</table></div>
54<div class="note"><table border="0" summary="Note">
55<tr>
56<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
57<th align="left">Note</th>
58</tr>
59<tr><td align="left" valign="top"><p>
60          Segmented stacks can only be used with <a class="link" href="../cc.html#cc"><span class="emphasis"><em>callcc()</em></span></a>
61          (using <a class="link" href="../ff/implementations__fcontext_t__ucontext_t_and_winfiber.html#implementation"><span class="emphasis"><em>ucontext_t</em></span></a>)
62        </p></td></tr>
63</table></div>
64<p>
65        .
66      </p>
67<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">context</span><span class="special">/</span><span class="identifier">segmented_stack</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
68
69<span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="identifier">traitsT</span> <span class="special">&gt;</span>
70<span class="keyword">struct</span> <span class="identifier">basic_segmented_stack</span> <span class="special">{</span>
71    <span class="keyword">typedef</span> <span class="identifier">traitT</span>  <span class="identifier">traits_type</span><span class="special">;</span>
72
73    <span class="identifier">basic_segmented_stack</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span> <span class="special">=</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">default_size</span><span class="special">());</span>
74
75    <span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
76
77    <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&amp;);</span>
78<span class="special">}</span>
79
80<span class="keyword">typedef</span> <span class="identifier">basic_segmented_stack</span><span class="special">&lt;</span> <span class="identifier">stack_traits</span> <span class="special">&gt;</span> <span class="identifier">segmented_stack</span><span class="special">;</span>
81</pre>
82<h5>
83<a name="context.stack.segmented.h0"></a>
84        <span class="phrase"><a name="context.stack.segmented._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"></a></span><a class="link" href="segmented.html#context.stack.segmented._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"><code class="computeroutput"><span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">()</span></code></a>
85      </h5>
86<div class="variablelist">
87<p class="title"><b></b></p>
88<dl class="variablelist">
89<dt><span class="term">Preconditions:</span></dt>
90<dd><p>
91              <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum</span><span class="special">:</span><span class="identifier">size</span><span class="special">()</span>
92              <span class="special">&lt;=</span> <span class="identifier">size</span></code>
93              and <code class="computeroutput"><span class="special">!</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">&amp;&amp;</span>
94              <span class="special">(</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum</span><span class="special">:</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&gt;=</span> <span class="identifier">size</span><span class="special">)</span></code>.
95            </p></dd>
96<dt><span class="term">Effects:</span></dt>
97<dd><p>
98              Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code>
99              Bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture
100              (the stack grows downwards/upwards) the stored address is the highest/lowest
101              address of the stack.
102            </p></dd>
103</dl>
104</div>
105<h5>
106<a name="context.stack.segmented.h1"></a>
107        <span class="phrase"><a name="context.stack.segmented._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"></a></span><a class="link" href="segmented.html#context.stack.segmented._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code class="computeroutput"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span>
108        <span class="special">&amp;</span> <span class="identifier">sctx</span><span class="special">)</span></code></a>
109      </h5>
110<div class="variablelist">
111<p class="title"><b></b></p>
112<dl class="variablelist">
113<dt><span class="term">Preconditions:</span></dt>
114<dd><p>
115              <code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum</span><span class="special">:</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span></code> and <code class="computeroutput"><span class="special">!</span>
116              <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
117              <span class="special">&amp;&amp;</span> <span class="special">(</span>
118              <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum</span><span class="special">:</span><span class="identifier">size</span><span class="special">()</span>
119              <span class="special">&gt;=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>.
120            </p></dd>
121<dt><span class="term">Effects:</span></dt>
122<dd><p>
123              Deallocates the stack space.
124            </p></dd>
125</dl>
126</div>
127<div class="note"><table border="0" summary="Note">
128<tr>
129<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
130<th align="left">Note</th>
131</tr>
132<tr><td align="left" valign="top"><p>
133          If the library is compiled for segmented stacks, <span class="emphasis"><em>segmented_stack</em></span>
134          is the only available stack allocator.
135        </p></td></tr>
136</table></div>
137</div>
138<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
139<td align="left"></td>
140<td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p>
141        Distributed under the Boost Software License, Version 1.0. (See accompanying
142        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>)
143      </p>
144</div></td>
145</tr></table>
146<hr>
147<div class="spirit-nav">
148<a accesskey="p" href="fixedsize.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.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_traits.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
149</div>
150</body>
151</html>
152