Stack allocation naturally has several advantages, such as not having to worry about freeing memory after allocation etc. (It has some disadvantages too, like not having as refined a control as dynamic allocation as to when an item is freed; "freeing" only occurs when the function call ends). However the danger with allocating on the stack is that of stack smashing, a very big danger indeed. What techniques do you use to determine beforehand (if possible) maximum memory usage bounds (naturally this would require keeping track of the possible call graphs especially wrt recursion)?

Also, what are some techniques to determine memory bounds beforehand in general including for dynamic allocation using malloc() and such?

For example, some things would be hard/impossible to predict before hand like say a linked list that is populated by the user, but there are many cases where it might be quite possible to compute bounds beforehand by various static analysis techniques.