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

Click here to view the latest version of this page.

Stack allocation

Class guarded_stack_allocator
Template simple_stack_allocator< size_t, size_t, size_t >
Free function pagesize()

A fcontext_t requires a stack which will be allocated/deallocated by a StackAllocator. Boost.Context provides the default implementation stack_allocator but a customized StackAllocator can be used instead.

StackAllocator concept

A StackAllocator must satisfy the StackAllocator concept requirements shown in the following table, in which a is an object of a StackAllocator type, p is a void *, and s is a std::size_t:


return type


a.allocate( s)

void *

returns a pointer to s bytes allocated from the stack

a.deallocate( p, s)


deallocates s bytes of memory beginning at p, a pointer previously returned by a.allocate()

[Important] Important

The implementation of allocate() might include logic to protect against exceeding the context's available stack size rather than leaving it as undefined behaviour.

[Important] Important

Calling deallocate() with a pointer not returned by allocate() results in undefined behaviour.

[Note] Note

The stack is not required to be aligned; alignment takes place inside make_fcontext().

[Note] Note

Depending on the architecture allocate() returns an address from the top of the stack (growing downwards) or the bottom of the stack (growing upwards).