4 ms·
It should be possible to do this without malloc(), by allocating the co-stack as an array within the current stack. Something like this... char stack[STACK
by userbinator 12y ago
It should be possible to do this without malloc(), by allocating the co-stack as an array within the current stack. Something like this...
char stack[STACK_SIZE];
int anchor_[unoptimisable_];
char filler_[(char*)&anchor_ - (char*)(stack + STACK_SIZE)];
...
(Haven't tested it, but it's basically the same principle. The same caveats about stack layout and VLAs apply.)
- rumcajz 12y agoExcept that if the parent function terminated before the coroutine it have launched, you would get memory overwrites.
- mtanski 12y agoYou would also need to align the stack per. target requirements (gcc keyword, or offset the address). The aliment guarantees for char[] placed on stack are probably insufficient for many machines.
- userbinator 12y agoIf none of the variables on the stack are smaller than your desired alignment size, and the stack starts out aligned (which it should), then it will remain aligned.