• 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 protected_fixedsize</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. Coroutine2">
8<link rel="up" href="../stack.html" title="Stack allocation">
9<link rel="prev" href="../stack.html" title="Stack allocation">
10<link rel="next" href="pooled_fixedsize.html" title="Class pooled_fixedsize_stack">
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="../stack.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="pooled_fixedsize.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="coroutine2.stack.protected_fixedsize"></a><a class="link" href="protected_fixedsize.html" title="Class protected_fixedsize">Class <span class="emphasis"><em>protected_fixedsize</em></span></a>
28</h3></div></div></div>
29<p>
30        <span class="bold"><strong>Boost.Coroutine2</strong></span> provides the class <span class="emphasis"><em>protected_fixedsize_stack</em></span>
31        which models the <span class="emphasis"><em>stack-allocator concept</em></span>. It appends
32        a guard page at the end of each stack to protect against exceeding the stack.
33        If the guard page is accessed (read or write operation) a segmentation fault/access
34        violation is generated by the operating system.
35      </p>
36<div class="important"><table border="0" summary="Important">
37<tr>
38<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/src/images/important.png"></td>
39<th align="left">Important</th>
40</tr>
41<tr><td align="left" valign="top"><p>
42          Using <span class="emphasis"><em>protected_fixedsize_stack</em></span> is expensive. That
43          is, launching a new coroutine with a new stack is expensive; the allocated
44          stack is just as efficient to use as any other stack.
45        </p></td></tr>
46</table></div>
47<div class="note"><table border="0" summary="Note">
48<tr>
49<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
50<th align="left">Note</th>
51</tr>
52<tr><td align="left" valign="top"><p>
53          The appended <code class="computeroutput"><span class="identifier">guard</span> <span class="identifier">page</span></code>
54          is <span class="bold"><strong>not</strong></span> mapped to physical memory, only
55          virtual addresses are used.
56        </p></td></tr>
57</table></div>
58<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">coroutine2</span><span class="special">/</span><span class="identifier">protected_fixedsize</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
59
60<span class="keyword">struct</span> <span class="identifier">protected_fixedsize</span> <span class="special">{</span>
61    <span class="identifier">protected_fixesize</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>
62
63    <span class="identifier">stack_context</span> <span class="identifier">allocate</span><span class="special">();</span>
64
65    <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>
66<span class="special">}</span>
67</pre>
68<h5>
69<a name="coroutine2.stack.protected_fixedsize.h0"></a>
70        <span class="phrase"><a name="coroutine2.stack.protected_fixedsize._code__phrase_role__identifier__stack_context__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special______phrase___code_"></a></span><a class="link" href="protected_fixedsize.html#coroutine2.stack.protected_fixedsize._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>
71      </h5>
72<div class="variablelist">
73<p class="title"><b></b></p>
74<dl class="variablelist">
75<dt><span class="term">Preconditions:</span></dt>
76<dd><p>
77              <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>
78              <span class="special">&lt;=</span> <span class="identifier">size</span></code>
79              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>
80              <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>.
81            </p></dd>
82<dt><span class="term">Effects:</span></dt>
83<dd><p>
84              Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code>
85              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
86              (the stack grows downwards/upwards) the stored address is the highest/lowest
87              address of the stack.
88            </p></dd>
89</dl>
90</div>
91<h5>
92<a name="coroutine2.stack.protected_fixedsize.h1"></a>
93        <span class="phrase"><a name="coroutine2.stack.protected_fixedsize._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="protected_fixedsize.html#coroutine2.stack.protected_fixedsize._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>
94        <span class="special">&amp;</span> <span class="identifier">sctx</span><span class="special">)</span></code></a>
95      </h5>
96<div class="variablelist">
97<p class="title"><b></b></p>
98<dl class="variablelist">
99<dt><span class="term">Preconditions:</span></dt>
100<dd><p>
101              <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>
102              <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span>
103              <span class="special">&amp;&amp;</span> <span class="special">(</span>
104              <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>
105              <span class="special">&gt;=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>.
106            </p></dd>
107<dt><span class="term">Effects:</span></dt>
108<dd><p>
109              Deallocates the stack space.
110            </p></dd>
111</dl>
112</div>
113</div>
114<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
115<td align="left"></td>
116<td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p>
117        Distributed under the Boost Software License, Version 1.0. (See accompanying
118        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>)
119      </p>
120</div></td>
121</tr></table>
122<hr>
123<div class="spirit-nav">
124<a accesskey="p" href="../stack.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="pooled_fixedsize.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
125</div>
126</body>
127</html>
128