Re: How to calculate the stack and heap size



ivan wrote:
Hi,

How can we calculate the stack and heap size requried by a C program.
Is there any specific formula used?

There is no standard way to calculate the stack size required, since 1) The C standard does not require a stack 2) You can't tell whether local variables will have memory associated at all, they might just be kept in registers or the compiler may find a way to eliminate some all together 3) There could be any or no padding between parameters

You can estimate it if you know how your implementation does things, although if you use recursion this can be very difficult.

There is no standard way to determine how much heap us used because
1) The C standard does not require a heap
2) Different heap management schemes have different overheads
3) It depends on how good your implementation is at reusing freed memory

Again, if you know your implementation well enough it may be possible to estimate this.

Please suggest.

I suggest that you ask somewhere dedicated to your system since it is highly system specific. This suggestion is for your benefit as much as ours.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.




Relevant Pages

  • Re: difference between stack & heap (general, for a newbie)
    ... >> The stack is used to allocate temporary objects while the heap is used ... > To the best of my knowledge, the standard does not require any such ...
    (comp.lang.cpp)
  • Re: Storage of Variables
    ... The heap is specifically defined in the C language AFAICR. ... The heap is not in the index of the standard. ... The stack and the data segment are generally identical. ...
    (comp.os.linux.misc)
  • Re: about memory model
    ... In most C *implementations* you have a stack and a heap. ... language itself (i.e., the standard) doesn't refer to either. ...
    (comp.lang.c)
  • Re: Some Questions Asked in Interview
    ... The standard C language neither recognizes the term ... |> 'heap', nor the term 'stack', and thus the question doesn't actually ... |> 'stack' are eligible to store static variables, ...
    (comp.lang.c)
  • Re: Off Topic: Stack vs. Heap
    ... > Is the concept of stack and heap completely independent of the standard? ... The standard defines static, dynamic and automatic storage duration, ...
    (comp.lang.cpp)