Very Large Stack Variables
The other major cause of a stack overflow results from an attempt to allocate more memory on the stack than will fit, for example by creating local array variables that are too large. For this reason some authors recommend that arrays larger than a few kilobytes should be allocated dynamically instead of as a local variable.
An example of a very large stack variable in C:
int foo { double x; }The declared array consumes 8 megabytes of data (assuming each double is 8 bytes); if this is more memory than is available on the stack (as set by thread creation parameters or operating system limits), a stack overflow will occur.
Stack overflows are made worse by anything that reduces the effective stack size of a given program. For example, the same program being run without multiple threads might work fine, but as soon as multi-threading is enabled the program will crash. This is because most programs with threads have less stack space per thread than a program with no threading support. Similarly, people new to kernel development are usually discouraged from using recursive algorithms or large stack buffers.
Read more about this topic: Stack Overflow
Famous quotes containing the words large, stack and/or variables:
“The hearts of Afro-American women are too warm and too large for race hatred. Long suffering has so chastened them that they are developing a special sense of sympathy for all who suffer and fail of justice.”
—Fannie Barrier Williams (18551944)
“What is a farm but a mute gospel? The chaff and the wheat, weeds and plants, blight, rain, insects, sunit is a sacred emblem from the first furrow of spring to the last stack which the snow of winter overtakes in the fields.”
—Ralph Waldo Emerson (18031882)
“Science is feasible when the variables are few and can be enumerated; when their combinations are distinct and clear. We are tending toward the condition of science and aspiring to do it. The artist works out his own formulas; the interest of science lies in the art of making science.”
—Paul Valéry (18711945)