libcoro
1.0
Coroutine support library for C++20
|
Coroutine allocator emulates coroutine's stack to achieve stackful behaviour. More...
#include <stackful.h>
Coroutine allocator emulates coroutine's stack to achieve stackful behaviour.
Allocator is passed to the coroutine as first argument. It is always carried as value, so it must be copied. However the allocator acts as shared pointer, so copying is sharing. The allocator manages coroutine's stack, every called sub-coroutine can use the same stack. You only need to pass the instance to every sub-coroutine.
The stack is managed similar way as stack in GO language. It is allocated in segments. Everytime new coroutine is called, its frame is allocated in a segment. If there is no more space, new segment is allocated from the heap. When coroutine exits, the memory is released.
It is expected, that memory allocation is performed in reverse order then allocation. However sometimes can happen that order of deallocation of topmost frames is reversed. This situation is handled correctly, however the out of order deallocation doesn't free memory until top of the stack is released reaching the out of order deallocated block.
segment_size | size of segment and initial stack size |
Definition at line 41 of file stackful.h.