cppcoro icon indicating copy to clipboard operation
cppcoro copied to clipboard

Use custom allocator for when_all_ready_task objects in when_all_ready(std::vector<AWAITABLE>)

Open lewissbaker opened this issue 6 years ago • 0 comments

With the when_all_ready(std::vector<AWAITABLE>) overloads we need to allocate N coroutine frames, one for each awaitable in the list. As the number of coroutine frames that needs to be allocated is not known at compile time, the compiler will be unable to elide the allocation of the coroutine frames.

Rather than perform N separate memory allocations, it might be useful to use a custom allocator that allocates space for all N coroutine frames up front so that we only perform a single heap allocation.

We can't know the size of the coroutine frame at compile time so we'll need to initialise the allocator with the number of tasks that will need to be allocated. Then when the first task is created the allocator will be passed the coroutine frame size. We can then allocate a pool of size N * coroutine frame size and allocate subsequent coroutine frames from that pool.

lewissbaker avatar Oct 16 '17 05:10 lewissbaker