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:
“Friends serve central functions for children that parents do not, and they play a critical role in shaping childrens social skills and their sense of identity. . . . The difference between a child with close friendships and a child who wants to make friends but is unable to can be the difference between a child who is happy and a child who is distressed in one large area of life.”
—Zick Rubin (20th century)
“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)