stack / heap size limit

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
ahmad_h
New poster
Posts: 5
Joined: Wed Mar 23, 2005 1:27 pm

stack / heap size limit

Post by ahmad_h » Sat Nov 17, 2007 7:08 pm

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?

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Re: stack / heap size limit

Post by Moha » Thu Dec 06, 2007 12:58 am

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.

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo » Thu Dec 06, 2007 4:58 am

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.

helsywarner
New poster
Posts: 1
Joined: Mon Mar 30, 2015 9:20 am
Contact:

Re: stack / heap size limit

Post by helsywarner » Mon Mar 30, 2015 9:23 am

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

Post Reply

Return to “C”