4 ms·
> Add some space in each frame for potential instrumentation and you have your minimum. On exit just scan from the maximum stack to minimum looking for non-zer
by bsdetector 5y ago
> Add some space in each frame for potential instrumentation and you have your minimum.
On exit just scan from the maximum stack to minimum looking for non-zero.
If you have tests it should be easy to get within a few bytes of max stack used, which is probably just as good as instrumenting everything.
- viraptor 5y agoIt's possible, but you need to watch out for some cases. For example let's say your furthest function declares char foo[4096], but uses only a few bytes of it in your testing. Your measurement will be 4k short.
- bsdetector 5y agoIt has to be a leaf function or there would be stack frames after, and no local variables after the array, and the function doesn't push anything onto the stack, and it has to be possible in ways not covered by tests to actually use that space. Sure, that could happen. But what the other guy was saying about being a compiler developer and being unsure how to calculate the maximum depth is that there are many, many ways to arrive at the wrong result. Resursion, argv/envp, varags, alloca, and so on. So unless you are going to spend a great deal of energy proving maximum depth you're going to be using an estimate of some sort. Thus, 'probably just as good'.