469,889 Members | 1,331 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

How to increase stack space/heap space

Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

May 11 '06 #1
9 6956
Ajay wrote:
Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

It's a platform-specific thing, more system related than even compiler
related -- and very much off topic here as it has nothing to do with the
language itself.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
May 11 '06 #2
"Ajay" <aj***********@gmail.com> wrote.
Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

Typically stacks are quite small. On the order of 16K or so.
It may be possible to increase stack size by specifying a compiler option.
However if you need a big stack, probably you have a poor program design.
Big objects are usually varaible in size, and best on the heap.

Usually the compiler will allow all available memory to be allocated on the
heap. In a multi-user system, the maximum allowed is usually set by the
system administrator. In a single user system, usually the only way to
increase ehap size is to buy more meory chips.
--
www.personal.leeds.ac.uk/~bgy1mm

May 11 '06 #3
Malcolm wrote:
"Ajay" <aj***********@gmail.com> wrote.
Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

Typically stacks are quite small. On the order of 16K or so.


Sorry, I can't let this go, while off topic, it is also wrong.

There isn't a typical stack size as there isn't a typical environment,
there might not even be a stack. A multi-user system may default to 1
or 2 Mb of stack per thread, while an embedded one may be configured for
a few tens or hundreds of bytes.

The answer is very platform specific, thus off topic here.
It may be possible to increase stack size by specifying a compiler option.
However if you need a big stack, probably you have a poor program design.
Big objects are usually varaible in size, and best on the heap.
Again, wrong. You might have a completely static design.
Usually the compiler will allow all available memory to be allocated on the
heap. In a multi-user system, the maximum allowed is usually set by the
system administrator. In a single user system, usually the only way to
increase ehap size is to buy more meory chips.


This has nothing to do with the compiler, or C.

--
Ian Collins.
May 11 '06 #4
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4c*************@individual.net...
Malcolm wrote:
"Ajay" <aj***********@gmail.com> wrote.
Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

Typically stacks are quite small. On the order of 16K or so.


Sorry, I can't let this go, while off topic, it is also wrong.


It's beyond wrong -- there's no guarantee that a "stack" or "heap" even
exists, much less what size it is.
There isn't a typical stack size as there isn't a typical environment,
there might not even be a stack. A multi-user system may default to 1
or 2 Mb of stack per thread, while an embedded one may be configured for
a few tens or hundreds of bytes.

The answer is very platform specific, thus off topic here.


<OT>
Most systems I'm familiar with have the heap grow upward from the "bottom"
of user memory and the stack grow "downward" from the top of user memory.
Either can grow until it meets the other, at which point the program usually
crashes within short order.

The only time you have a fixed stack size is when you create additional
threads; one thread's stack will grow down towards the heap as above, but
other threads' stacks will grow into another stack, which will (eventually)
cause problems even if there's plenty of memory left. This is when compiler
options on stack size become relevant. Of course, C doesn't mention threads
either.
</OT>

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
*** Posted via a free Usenet account from http://www.teranews.com ***
May 11 '06 #5
On Thu, 11 May 2006 21:36:12 +0100, "Malcolm"
<re*******@btinternet.com> wrote in comp.lang.c:
"Ajay" <aj***********@gmail.com> wrote.
Hi all,
Can I know what is the stack space and heap space allocated by
the compiler.Can i increase it or decrease it.if yes,pleae tell me
theway to do it.Thanks in advance. Cheers, Ajay

Typically stacks are quite small. On the order of 16K or so.


I'd like to see a 16K stack on an 8051...
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
May 12 '06 #6
Jack Klein wrote:

I'd like to see a 16K stack on an 8051...


I'd like to see a stack on an 8051...
(the setup I used had a 128byte call stack, and no stack variables)

May 12 '06 #7
"Ian Collins" <ia******@hotmail.com> wrote
Typically stacks are quite small. On the order of 16K or so.


Sorry, I can't let this go, while off topic, it is also wrong.

There isn't a typical stack size as there isn't a typical environment,
there might not even be a stack. A multi-user system may default to 1
or 2 Mb of stack per thread, while an embedded one may be configured for
a few tens or hundreds of bytes.

The answer is very platform specific, thus off topic here.

What you have forgotten is that, in C programs, the stack size is
logarithmic.

So if we have a program of 10 functions using 1 Kb of stack space, and a
program with 100 functions uses 2Kb, a program of 1000 functions will take
3Kb, and so forth.

The places this breaks down are some types of recursive algorithms, but not
most of them, since most recursive algorithms also use logarithmic stack
size, and if we allow big items to be placed on the stack. Most C
programmers use the convention that big items are not placed on the stack.
There is a little bit of fuzziness in what is "big".

So the question and answer isn't very platform-specific after all. Stack
usage varies from program to program, of course, but not by as much as the
variation in program size might lead you to believe.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm

May 13 '06 #8
Malcolm wrote:
"Ian Collins" <ia******@hotmail.com> wrote
Typically stacks are quite small. On the order of 16K or so.
Sorry, I can't let this go, while off topic, it is also wrong.

There isn't a typical stack size as there isn't a typical environment,
there might not even be a stack. A multi-user system may default to 1
or 2 Mb of stack per thread, while an embedded one may be configured for
a few tens or hundreds of bytes.

The answer is very platform specific, thus off topic here.


What you have forgotten is that, in C programs, the stack size is
logarithmic.

Where do you get that from?
So if we have a program of 10 functions using 1 Kb of stack space, and a
program with 100 functions uses 2Kb, a program of 1000 functions will take
3Kb, and so forth.
You could have a program with ten functions where the first calls the
others in turn, or where each calls the next. The stack usage (assuming
for this argument that there is a stack) would be quite different. All
it takes is for one or two functions in the application to use a large
amount of stack space and any speculation is useless.
The places this breaks down are some types of recursive algorithms, but not
most of them, since most recursive algorithms also use logarithmic stack
size, and if we allow big items to be placed on the stack. Most C
programmers use the convention that big items are not placed on the stack.
There is a little bit of fuzziness in what is "big".
Not in a static design they don't.

The field is too broad to draw general conclusions.
So the question and answer isn't very platform-specific after all. Stack
usage varies from program to program, of course, but not by as much as the
variation in program size might lead you to believe.


I didn't mention program size.

--
Ian Collins.
May 13 '06 #9
Ian Collins wrote:

Malcolm wrote:
"Ian Collins" <ia******@hotmail.com> wrote
Typically stacks are quite small. On the order of 16K or so. off topic


That says it all.

--
pete
May 14 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Kevin Grigorenko | last post: by
2 posts views Thread by news.tkdsoftware.com | last post: by
10 posts views Thread by Shuo Xiang | last post: by
1 post views Thread by Geiregat Jonas | last post: by
3 posts views Thread by nahur | last post: by
9 posts views Thread by shine | last post: by
9 posts views Thread by coder_lol | last post: by
11 posts views Thread by Nehil | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.