3 ms·
Its not super hard if you don't give a care about your local stack space. Just over-allocate a bunch of static arrays on your stack. Stack variables in C99 (an
by dragontamer 7y ago
Its not super hard if you don't give a care about your local stack space. Just over-allocate a bunch of static arrays on your stack.
Stack variables in C99 (and most C++ compilers supporting C99) can even have a dynamic, run-time determined length. It compiles down to a "add esp, (blah)" command, if anyone is curious, so its super efficient.
I prefer stack-based allocations in my code. I only use heap-variables if I'm passing data between threads. If you need to pass data "up" your functions, then its a parameter (that is passed in on the stack). I would argue that stack-based variables are preferred in C++ due to RAII.