title: Are stackless C++20 coroutines a problem?
body: <p>Based on the following it looks like coroutines in C++20 will be stackless. </p>
  
  <p><a href="https://en.cppreference.com/w/cpp/language/coroutines" rel="noreferrer">https://en.cppreference.com/w/cpp/language/coroutines</a></p>
  
  <p>I'm concerned for many reasons:</p>
  
  <ol>
  <li>On embedded systems heap allocation is often not acceptable.</li>
  <li>When in low level code, nesting of co_await would be useful (I don't believe stackless co-routines allow this).</li>
  </ol>
  
  <blockquote>
    <p>With a stackless coroutine, only the top-level routine may be
    suspended. Any routine called by that top-level routine may not itself
    suspend. This prohibits providing suspend/resume operations in
    routines within a general-purpose library.</p>
  </blockquote>
  
  <p><a href="https://www.boost.org/doc/libs/1_57_0/libs/coroutine/doc/html/coroutine/intro.html#coroutine.intro.stackfulness" rel="noreferrer">https://www.boost.org/doc/libs/1_57_0/libs/coroutine/doc/html/coroutine/intro.html#coroutine.intro.stackfulness</a></p>
  
  <ol start="3">
  <li><p>More verbose code because of the need for custom allocators and memory pooling.</p></li>
  <li><p>Slower if the task waits for the operating system to allocate it some memory (without memory pooling).</p></li>
  </ol>
  
  <p>Given these reasons, I'm really hoping I'm very wrong about what the current coroutines are.</p>
  
  <p>The question has three parts:</p>
  
  <ol>
  <li>Why would C++ choose to use stackless coroutines?</li>
  <li>Regarding allocations to save state in stackless coroutines. Can I use alloca() to avoid any heap allocations that would normally be used for the coroutine creation. </li>
  </ol>
  
  <blockquote>
    <p>coroutine state is allocated on the heap via non-array
    operator new.
    <a href="https://en.cppreference.com/w/cpp/language/coroutines" rel="noreferrer">https://en.cppreference.com/w/cpp/language/coroutines</a></p>
  </blockquote>
  
  <ol start="3">
  <li>Are my assumptions about the c++ coroutines wrong, why?</li>
  </ol>
  
  <p>EDIT:</p>
  
  <p>I'm going through the cppcon talks for the coroutines now, if I find any answers to my own question I'll post it (nothing so far).</p>
  
  <p><em>CppCon 2014: Gor Nishanov "await 2.0: Stackless Resumable Functions"</em></p>
  
  <p><a href="https://www.youtube.com/watch?v=KUhSjfSbINE" rel="noreferrer">https://www.youtube.com/watch?v=KUhSjfSbINE</a></p>
  
  <p><em>CppCon 2016: James McNellis “Introduction to C++ Coroutines"</em></p>
  
  <p><a href="https://www.youtube.com/watch?v=ZTqHjjm86Bw" rel="noreferrer">https://www.youtube.com/watch?v=ZTqHjjm86Bw</a></p>