Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Stack overflow
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===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 [[C dynamic memory allocation|allocated dynamically]] instead of as a local variable.<ref name="onlamp">{{cite web | last = Feldman | first = Howard | title = Modern Memory Management, Part 2 | url = http://www.onlamp.com/pub/a/onlamp/2005/11/23/memory-management-2.html | date = 2005-11-23 | access-date = 2007-08-14 | archive-date = 2012-09-20 | archive-url = https://web.archive.org/web/20120920112622/http://onlamp.com/pub/a/onlamp/2005/11/23/memory-management-2.html | url-status = dead }}</ref> An example of a very large stack variable in [[C (programming language)|C]]: <syntaxhighlight lang="c"> int foo() { double x[1048576]; } </syntaxhighlight> On a C implementation with 8 byte [[Double-precision floating-point format|double-precision floats]], the declared array consumes 8 [[megabytes]] of data; 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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)