Question

What warning signs are there that my stack memory space is bloated, and at what point should I start using heap memory? And, are there differences between processors, I'm thinking about stack size limitations?

Était-ce utile?

La solution

The size of the stack can be specified during linking. The exact method of doing so depends on your toolchain. Other than 32-bit versus 64-bit processors, I don't know of any processor-based limitations on stack size.

As to if you are using too much, there's no right or wrong answer to that, it is a design question and depends on your requirements. Since the stack size is set during linking, it will limit your maximum data more severely than using the heap, generally speaking at any rate. On the other hand, stack allocations and deallocations are faster than using the heap.

Autres conseils

You can normally control the size of the stack using command line options to the compiler and linker.

Are you getting any stack overflows (the error, not the site)? That would be a big clue that you are pushing the limits of your stack.

I think you would need to start out by figuring out how big your default stack is in your app, then having a think about what you are stuffing onto it.

As many of the other people have said, the size of the stack is controllable through command line options.

With regards to heap usage, I tend to stick to this:

If I can dynamically allocate class objects at the beginning of my program, I will do so. I tend not to dynamically allocate or delete dynamically allocated object mid-run because it fragments memory.

Primitive objects are normally kept on the stack as their size is negligible.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top