How to increase stack space/heap space

A

Ajay

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
 
A

Artie Gold

Ajay said:
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
 
M

Malcolm

Ajay said:
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.
 
I

Ian Collins

Malcolm said:
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.
 
S

Stephen Sprunk

Ian Collins said:
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


*** ***
 
O

Old Wolf

Jack said:
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)
 
M

Malcolm

Ian Collins said:
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.
 
I

Ian Collins

Malcolm said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top