In C++; How big should an object [that will be transferred between functions] be before I consider delegating it to the heap

code-qualityheapperformancepointersstack

In my day to day programming, I tend to use very few pointers, not only because I want to keep my code simple and error free, but because I assume that the programming that I do does not have any objects large enough to benefit from delegating them to the heap.

At most; my largest object would probably be a QString of maybe a million characters.

However, I just assume it is not large enough to benefit from the heap; How should I go about estimating whether an object I have created is large enough to benefit from being turned into a pointer?

Best Answer

Since most implementations take the heap and the stack from the same block of memory (growing from either end) it doesn't matter. Size is not a reason to prefer the heap over the stack. The lifetime of your object is. Should it die once it goes out of scope or not? If not, when?