3 ms·
>Doesn't perform any heap memory allocations That's fascinating, I wonder how they managed that (unless they used cheats like sbrk of course).
by faissaloo 7y ago
>Doesn't perform any heap memory allocations
That's fascinating, I wonder how they managed that (unless they used cheats like sbrk of course).
- dragontamer 7y agoIts 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.
- oso2k 7y ago`sbrk` modifies the heap [0]. [0] https://linux.die.net/man/2/sbrk https://linux.die.net/man/2/sbrk
- faissaloo 7y agoOh right I was confusing it with alloca() http://man7.org/linux/man-pages/man3/alloca.3.html http://man7.org/linux/man-pages/man3/alloca.3.html