Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class segmented_stack

Boost.Context supports usage of a segmented_stack, e. g. the size of the stack grows on demand. The coroutine is created with a minimal stack size and will be increased as required. Class segmented_stack models the stack-allocator concept. In contrast to protected_fixedsize_stack and fixedsize_stack it creates a stack which grows on demand.

[Note] Note

Segmented stacks are currently only supported by gcc from version 4.7 clang from version 3.4 onwards. In order to use a segmented_stack Boost.Context must be built with property segmented-stacks, e.g. toolset=gcc segmented-stacks=on and applying BOOST_USE_SEGMENTED_STACKS at b2/bjam command line.

[Note] Note

Segmented stacks can only be used with callcc() (using ucontext_t)

.

#include <boost/context/segmented_stack.hpp>

template< typename traitsT >
struct basic_segmented_stack {
    typedef traitT  traits_type;

    basic_segmented_stack(std::size_t size = traits_type::default_size());

    stack_context allocate();

    void deallocate( stack_context &);
}

typedef basic_segmented_stack< stack_traits > segmented_stack;
stack_context allocate()

Preconditions:

traits_type::minimum:size() <= size and ! traits_type::is_unbounded() && ( traits_type::maximum:size() >= size).

Effects:

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)

Preconditions:

sctx.sp is valid, traits_type::minimum:size() <= sctx.size and ! traits_type::is_unbounded() && ( traits_type::maximum:size() >= sctx.size).

Effects:

Deallocates the stack space.

[Note] Note

If the library is compiled for segmented stacks, segmented_stack is the only available stack allocator.


PrevUpHomeNext