Boost C++ Libraries 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 for the latest Boost documentation.

Class stack_allocator

Boost.Coroutine provides the class boost::coroutines::stack_allocator which models the stack-allocator concept. It appends a guard page at the end of each stack to protect against exceeding the stack. If the guard page is accessed (read or write operation) a segmentation fault/access violation is generated by the operating system.

[Note] Note

The appended guard page is not mapped to physical memory, only virtual addresses are used.

class stack_allocator
    static bool is_stack_unbound();

    static std::size_t maximum_stacksize();

    static std::size_t default_stacksize();

    static std::size_t minimum_stacksize();

    void allocate( stack_context &, std::size_t size);

    void deallocate( stack_context &);
static bool is_stack_unbound()


Returns true if the environment defines no limit for the size of a stack.

static std::size_t maximum_stacksize()


is_stack_unbound() returns false.


Returns the maximum size in bytes of stack defined by the environment.

static std::size_t default_stacksize()


Returns a default stack size, which may be platform specific. If the stack is unbound then the present implementation returns the maximum of 64 kB and minimum_stacksize().

static std::size_t minimum_stacksize()


Returns the minimum size in bytes of stack defined by the environment (Win32 4kB/Win64 8kB, defined by rlimit on POSIX).

void allocate( stack_context & sctx, std::size_t size)


minimum_stacksize() > size and ! is_stack_unbound() && ( maximum_stacksize() < size).


Allocates memory of at least size Bytes and stores a pointer to the stack and its actual size in sctx.


Returns pointer to the start address of the new stack. Depending on the architecture the stack grows downwards/upwards the returned address is the highest/lowest address of the stack.

void deallocate( stack_context & sctx)


sctx.sp is valid, minimum_stacksize() > sctx.size and ! is_stack_unbound() && ( maximum_stacksize() < size).


Deallocates the stack space.