Page 1 of 1

stack / heap size limit

Posted: Sat Nov 17, 2007 7:08 pm
by ahmad_h
I wanted to inquirea that is it possible to get a Runtime Error because of a big stack size. If so what is the limit; how much stack space you are allowed by the judge. I have looked over the forums but couldn't find an answer...if i'm mistaken please point me to it.

I know I have put this message in the C area. What are the answers to these questions for C++ submissions?

Also is there a limit put on the heap size? Is the limit on stack and heap size (if it exists) dependent on different questions? The post http://online-judge.uva.es/board/viewtopic.php?t=7430 says that the exact cause of RE would be told to the user. How can I exactly get to know the cause of my RE....where is it supposed to appear?

Re: stack / heap size limit

Posted: Thu Dec 06, 2007 12:58 am
by Moha
ahmad_h wrote:I wanted to inquirea that is it possible to get a Runtime
Error because of a big stack size.
Yes, there is no actual limitation between the difference segments of a code, so increasing in stack unreasonably would corrupt another segment (it depends on the OS).
ahmad_h wrote:If so what is the limit; how much stack space you are allowed by the judge. I have looked over the forums but couldn't find an answer...if i'm mistaken please point me to it.
The value doesn't matter, it is enough to solve the all of the recursive problems.
ahmad_h wrote:I know I have put this message in the C area. What are the answers to these questions for C++ submissions?
Same.
ahmad_h wrote:Also is there a limit put on the heap size? Is the limit on stack and heap size (if it exists) dependent on different questions? The post http://online-judge.uva.es/board/viewtopic.php?t=7430 says that the exact cause of RE would be told to the user. How can I exactly get to know the cause of my RE....where is it supposed to appear?
The limitation on the heap size is as the problem indicates for example 32MB. Of course you can not use all of this space as the heap, But your heap size together with the code segment size can not go beyond this limitation.

Posted: Thu Dec 06, 2007 4:58 am
by sclo
It is possible to get stack overflow. I got it when I tried doing dfs on a graph with more than 1 million vertices. Of course, it is easily fixable by using a stack to do dfs instead of doing dfs recursively.

Re: stack / heap size limit

Posted: Mon Mar 30, 2015 9:23 am
by helsywarner
Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM .

Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory . Element of the heap have no dependencies with each other and can always be accessed randomly at any time. You can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time.

You can use the stack if you know exactly how much data you need to allocate before compile time and it is not too big. You can use heap if you don't know exactly how much data you will need at runtime or if you need to allocate a lot of data. More about.......Stack and Heap

Warner