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 an old version of boost. Click here for the latest version's documentation home page.

Class guarded_stack_allocator

Boost.Context provides the class guarded_stack_allocator which models the StackAllocator concept 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 guarded_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( std::size_t size);

    void deallocate( void * sp, std::size_t size);
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( std::size_t size)


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


Allocates memory of size Bytes and appends one guard page at the end of the allocated memory.


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( void * sp, std::size_t size)


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


Deallocates the stack space.