Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 912967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:28:28+00:00 2026-05-15T17:28:28+00:00

This question is mystifying me for years and considering this site’s name, this is

  • 0

This question is mystifying me for years and considering this site’s name, this is the place to ask.

Why do we, programmers, still have this StackOverflow problem?

Why in every major language does the thread stack memory have to be statically allocated on thread creation?

I will speak in the context of C#/Java, because I use them most, but this is probably a broader problem.

Fixed stack size leads to huge problems:

  • There is no way to write a recursive algorithm unless you are absolutely sure that the depth of recursion is tiny. Linear memory complexity of the recursive algorithm is often unacceptable.
  • There is no cheap way to start new threads. You have to allocate huge block of memory for stack to account for all the possible uses of the thread.
  • Even if you don’t use very deep recursion, you always have a risk of running out of stack space for the reason that the stack size is an arbitrary fixed number. Considering that the StackOverflow is usually unrecoverable, this is a big problem in my eyes.

Now, if the stack was resized dynamically, all of the problems above would be much alleviated, because stack overflow would only be possible when there is a memory overflow.

But this is not the case yet. Why? Are there some fundamental limitations of modern CPUs which would make it impossible/inefficient? If you think about the performance hit that reallocations would impose, it should be acceptable because people use structures like ArrayList all the time without suffering much.

So, the question is, am I missing something and the StackOverflow is not a problem, or am I missing something and there are a lot of languages with dynamic stack, or is there some big reason for this being impossible/hard to implement?

Edit:
Some people said that performance would be a large problem, but consider this:

  • We leave the compiled code untouched. The stack access stays the same, thus the “usual case” performance stays the same.
  • We handle CPU exception which happens when the code tries to access the unallocated memory and launch our “reallocation” routine. Reallocations won’t be frequent because <put your usual ArrayList argument here>. Should work on most protected-mode CPUs without loss of performance. No?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:28:29+00:00Added an answer on May 15, 2026 at 5:28 pm

    I am going to summarize the arguments in the answers so far because I find no answer covering this topic good enough.

    Static stack investigation

    Motivation

    Not everyone needs it.

    • Most algorithms do not use deep recursion or a lot of threads, thus not a lot of people need dynamic stacks.
    • Dynamic stack would make an infinite-recursion stack overflow, which is an easy mistake to make, harder to diagnose. (memory overflow, while being as deadly as a stack overflow to the current process, is hazardous for other processess as well)
    • Every recursive algorithm can be emulated with a similar iterative one.

    Implementation difficulties

    Dynamic stack implementation turns out to be not as straightforward as it seems.

    • Stack resizing alone is not enough unless you have unlimited address space. You will sometimes need to relocate the stack as well.
    • Stack relocation would require updates for all the pointers to the data structures allocated on the stack. While it is straightforward (at least in managed languages) for the data in memory, there is no easy way to do the same for data in the CPU registers of the thread.
    • Some CPUs (microcontrollers in particular) implement the stack directly on hardware, separate from the main memory.

    Existing implementations

    There are some languages or runtime libraries that already have the dynamic stack feature or something similar to it.

    • Some runtime libraries (which?) do not pre-commit the entire block of memory allocated for stack. This can alleviate the problem, expecially for 64-bit systems, but not completely eliminate it.
    • Ira Baxter told us about PARLANSE, a language specifically designed for dealing with complex data structures with high degree of parallelism. It uses small heap-allocated “grains” of work instead of stack.
    • fuzzy lolipop told us that “Properly written Erlang doesn’t have stackoverflows!”
    • Google Go programming language is said to have a dynamic stack. (a link would be nice)

    I would like to see more examples here.

    I hope I didn’t forget any important pieces of information on this subject. Making this a community wiki so that anyone can add new information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is not as simple as it seems to be. I have 64
This question has been brought up before, and I have searched many of the
This question is in context with the problem mentioned in this thread . I'm
This question seems to have been asked a lot but all were trying to
This question answers pseudocode for roulette wheel selection . But it's for maximization problem.
This question is specific to Erlang, but may have general implications to other IO
This question would not have existed if AspectJ worked the same way as EJB
(This question is over 6 years old and probably no longer has any relevance.)
This question was very helpful, however I have a list control in my report,
This question is a bit different than most. My code works but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.