info about no. of stack frames...!!!!

R

Rajshekhar

Hi,
I would like to know who decides the limit on the number of stack
frames/pointers in a system for a program?
for e.g in a recursion program if it loops for 'n' times then
accordingly stack frames are incremented ..
my question is who decides the maximum no.of stack frames for a
program is it 1.system architecture or
2.compiler dependent or
3.implementation dependent.???

is this number is fixed or variable..??

TIA
Regards,
Rajshekhar
 
C

Chris Croughton

I would like to know who decides the limit on the number of stack
frames/pointers in a system for a program?

Probably no one, it just goes until the memory available for the
stack[1] runs out.
for e.g in a recursion program if it loops for 'n' times then
accordingly stack frames are incremented ..
my question is who decides the maximum no.of stack frames for a
program is it 1.system architecture or
Possibly.

2.compiler dependent or
Possibly.

3.implementation dependent.???
Possibly.

is this number is fixed or variable..??

Probably.

It's some combination of the above three variables, plus it could depend
on the configuration at that time (for instance how much memory is being
used by other programs). On embedded systems, for instance, it's common
to give each task (process) its own dedicated stack, the size determined
at build time, on some PC systems the stack grows down until it meets
the heap of free memory used by malloc(), on others it is in its own
memory space and can use swap space, etc.

On some systems the "stack frame" format is defined by hardware, on most
it is determined by the operating system needs. In general, your
question can't be answered without knowing the system, and it may not
even be answerable...

[1] Or whatever is used. On at least one system I know it uses a linked
list of 'frames', on another a pointer to the 'frame' is passed to the
called function in a register and the memory for the 'frame' comes from
wherever the calling code gets it.

Chris C
 
R

Richard Tobin

Rajshekhar said:
I would like to know who decides the limit on the number of stack
frames/pointers in a system for a program?

This is a property of the operating system or possibly the C
implementation, not the language.

A reasonable general-purpose operating system will give the user or
administrator some way to specify the maximum stack size. Obviously
this will be limited by the address space of the processor and the
amount of (virtual) memory on the system. The *number* of frames is
unlikely to be relevant, rather it will be the space they occupy.

For example, in unix there is a "setrlimit" system call that can be
used, and it can be accessed from the shell by using the "limit" or
"ulimit" command.

If you're using an embedded system, or an unreasonable general-purpose
one, then there are other possibilities, such as "it keeps going until
the system crashes".

-- Richard
 
C

CBFalconer

Chris said:
I would like to know who decides the limit on the number of stack
frames/pointers in a system for a program?

Probably no one, it just goes until the memory available for the
stack[1] runs out.

Please don't encourage this sort of off-topic query by answering
it, other than to redirect the OP to an appropriate newsgroup.
Besides being off-topic, in most cases the experts on the subject
are not here, and erroneous answers will go uncorrected.
 
N

Nagaraj L

It is only the system RAM memory limit that would restrict your program
from functioning.
 
S

SM Ryan

(e-mail address removed) (Rajshekhar) wrote:
# Hi,
# I would like to know who decides the limit on the number of stack
# frames/pointers in a system for a program?

System dependent. Some allow you specify in program start up, or link-load, or
elsewhere stack size limits; others do not. Those that do allow the limits to
be set, vary in how they set those limits. You'll need system specific code
or scripting for each different system.
 
J

Jonathan Bartlett

for e.g in a recursion program if it loops for 'n' times then
accordingly stack frames are incremented ..

Just as an aside, if you do a tail-recursive function, GCC can often
make it run in constant stack space. With a slightly different ABI it
would be possible to eliminate all tail-calls whether recursive or not,
but now I'm completely off-topic :)

Jon
 
S

SM Ryan

# It is only the system RAM memory limit that would restrict your program
# from functioning.

With VM its the segment size and/or available disc space. On some CPUs
its the hardware register size, like 65535 for an 80286. On some systems
it's some bozo who decides nobody will ever need more than a 640K of space
and wires that it into the operating system.
 
A

Alan Balmer

I would like to know who decides the limit on the number of stack
frames/pointers in a system for a program?

Probably no one, it just goes until the memory available for the
stack[1] runs out.

Please do the OP the service of directing him to a more appropriate
newsgroup, rather than answering such off-topic questions here.

To the OP - The answer to your question
1.system architecture or
2.compiler dependent or
3.implementation dependent.???

is Yes. Make your query in a newsgroup which deals with the system
architecture, compiler and implementation you are working with.
 
K

Keith Thompson

Nagaraj L said:
It is only the system RAM memory limit that would restrict your program
from functioning.

Not true. On many systems, virtual memory is bigger than physical
RAM. Also, the memory available to a given program may not be related
to the amount available to the entire system.

The details are off-topic. The C standard requires certain minimum
resource levels, but otherwise doesn't say anything about how much
memory is available to a program under what circumstances.
 

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

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top