Comment by oconnor663

1 day ago

Note that C++ coroutines use heap allocation to avoid the problems that Pin is solving, which is a pretty big carve-out from the "zero overhead principle" that C++ usually aims for. The long development time of async traits has also been related to Rust not heap allocating futures. Whether that performance+portability-vs-complexity tradeoff is worth it for any given project is, of course, a different question.

C++ coroutines must allocate at runtime as the allocation size isn't resolvable early enough at compile time to statically fix the allocation, but it's not required to be allocated from the heap (not that custom allocators are fun, but it is possible).

In any event it's essentially a stack frame so it's not a failure of zero-overhead, the stack frame will need to be somewhere.

Quite a lot of work was done in Clang at least to elide allocations for coroutines where the compiler can see enough information.