| Home | Libraries | People | FAQ | More

## Stack allocation

A fcontext_t requires a stack which will be allocated/deallocated by a StackAllocator. Boost.Context uses `stack_allocator` by default but a customized `stack allocator` can be passed to the context constructor instead. If a context is constructed it invokes allocate() function and by its destruction the stack gets released by deallocate().

#### 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`:

expression | return type | notes
--- | --- | ---
`a.allocate( s)` | `void *` | returns a pointer to `s` bytes allocated from the stack
`a.deallocate( p, s)` | `void` | deallocates `s` bytes of memory beginning at `p`, a pointer previously returned by `a.allocate()`

| 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
Calling `deallocate()` with a pointer not returned by `allocate()` results in undefined behaviour.

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