...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Boost.Coroutine2 provides the class pooled_fixedsize_stack
which models the stack-allocator concept. In contrast
to protected_fixedsize_stack it does not append a guard
page at the end of each stack. The memory is managed internally by boost::pool<>
.
#include <boost/coroutine2/pooled_fixedsize_stack.hpp> struct pooled_fixedsize_stack { pooled_fixedsize_stack(std::size_t size = traits_type::default_size()); stack_context allocate(); void deallocate( stack_context &); }
pooled_fixedsize_stack(std::size_t
stack_size,
std::size_t next_size, std::size_t max_size)
! traits_type::is_unbounded() &&
( traits_type::maximum:size() >= stack_size)
and 0 <
nest_size
.
Allocates memory of at least stack_size
Bytes and stores a pointer to the stack and its actual size in sctx
. Depending on the architecture
(the stack grows downwards/upwards) the stored address is the highest/lowest
address of the stack. Argument next_size
determines the number of stacks to request from the system the first
time that *this
needs to allocate system memory. The third argument max_size
controls how many memory might be allocated for stacks - a value of
zero means no uper limit.
stack_context allocate()
! traits_type::is_unbounded() &&
( traits_type::maximum:size() >= size)
.
Allocates memory of at least size
bytes and stores a pointer to the stack and its actual size in sctx
. Depending on the architecture
(the stack grows downwards/upwards) the stored address is the highest/lowest
address of the stack.
void deallocate( stack_context
& sctx)
sctx.sp
is valid, !
traits_type::is_unbounded()
&& (
traits_type::maximum:size()
>= sctx.size)
.
Deallocates the stack space.