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

PrevUpHomeNext

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:

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

static std::size_t maximum_stacksize()

Preconditions:

is_stack_unbound() returns false.

Returns:

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

static std::size_t default_stacksize()

Returns:

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:

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)

Preconditions:

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

Effects:

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

Returns:

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)

Preconditions:

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

Effects:

Deallocates the stack space.


PrevUpHomeNext