| Home | Libraries | People | FAQ | More

## Stack allocation

A coroutine uses internally a context which manages a set of registers and a stack. The memory used by the stack is allocated/deallocated via a stack-allocator which is required to model a stack-allocator concept.

#### stack-allocator concept

A stack-allocator must satisfy the stack-allocator concept requirements shown in the following table, in which `a` is an object of a stack-allocator type, `sctx` is a `stack_context`, and `size` is a `std::size_t`:

expression | return type | notes
--- | --- | ---
`a.allocate( sctx, size)` | `void` | creates a stack of at least `size` bytes and stores both values in `sctx`
`a.deallocate( sctx)` | `void` | deallocates the stack created 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 coroutine.

| 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).