Originally posted by DavidBrown
View Post
The benefit of arrays on stack is that not only can you avoid the overhead of dynamic allocation, but the address range is also likely to be very warm in the cache hierarchy. I've taken advantage of this, to very good effect. The best example was to dynamically build a small image processing pipeline on the stack, have the leaf-node function pull data through it, and then teardown the whole thing as the setup functions for each stage returned. The stack-allocated data structures held at most a couple scanlines of image data, each.
Obviously, another argument against them would be the risk of security exploits via payloads that can trigger out-of-bounds accesses. Shadow stacks should do a lot to mitigate that scenario, though I'm generally much more reluctant to use stack for things like string-processing.
Comment