473,548 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Should running a program at the smallest call stack depth be pursued?


Is there any value to pursuing program designs that mimimize
the mainline call stack? For example, within main() I could
code up something like:

while(GetMsg(m) )
DispatchMsg(m);

instead of doing Program.Run() from main() or even worse
calling Run() from the Program constructor.

Call Stack example 1:
main()
GetMsg()/DispatchMsg()

Call Stack example 2:

main()
Program::Progra m()
Program::Run()
GetMsg()/DispatchMsg()

Tony
Dec 7 '06 #1
6 1425
Tony wrote:
Is there any value to pursuing program designs that mimimize
the mainline call stack? For example, within main() I could
code up something like:

while(GetMsg(m) )
DispatchMsg(m);

instead of doing Program.Run() from main() or even worse
calling Run() from the Program constructor.

Call Stack example 1:
main()
GetMsg()/DispatchMsg()

Call Stack example 2:

main()
Program::Progra m()
Program::Run()
GetMsg()/DispatchMsg()

Tony
Given that your platform appears to be Win32, no. For certain embedded
systems with fixed/minimal stack, the answer may be yes.

It's platform and application dependent, and YMMV.

Dec 7 '06 #2

Tony wrote:
Is there any value to pursuing program designs that mimimize
the mainline call stack?
That's a general question. As with any optimisation question, the
general answer is "no need". That should be your starting point. There
are two sets of circumstances where you will change from "no" to "yes".

1. You have proven that the depth of your call-stack makes it
impossible for your program to meet its requirements.[*]
2. You have sufficient knowledge and experience of your compiler and
target platform that you know in advance that the depth of call-stack
you would like to write will make it impossible for your program to
meet its requirements.

If either of the above applies, and only you know that, then make the
optimisation.
[*] In this case the requirements will presumably be in terms of stack
size.

Gavin Deane

Dec 8 '06 #3

"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...
>
Tony wrote:
>Is there any value to pursuing program designs that mimimize
the mainline call stack?

That's a general question. As with any optimisation question, the
general answer is "no need".
I wasn't necessarily asking from an optimization standpoint. My concern
would be more from the robustness standpoint: if there's a larger surface
area for potential corruption, then maybe it's wise to minimize that.

Tony
Dec 8 '06 #4

Tony wrote:
"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...

Tony wrote:
Is there any value to pursuing program designs that mimimize
the mainline call stack?
That's a general question. As with any optimisation question, the
general answer is "no need".

I wasn't necessarily asking from an optimization standpoint. My concern
would be more from the robustness standpoint: if there's a larger surface
area for potential corruption, then maybe it's wise to minimize that.

Tony
Unless you have a specific threat in mind that you have very good
reason to think that trying to minimize stack height will help prevent
[note: I can't think of any], my feeling is that you're more likely to
introduce errors trying to minimize stack height than you are just
leaving it.

Evan

Dec 8 '06 #5

Tony wrote:
"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...

Tony wrote:
Is there any value to pursuing program designs that mimimize
the mainline call stack?
That's a general question. As with any optimisation question, the
general answer is "no need".

I wasn't necessarily asking from an optimization standpoint. My concern
would be more from the robustness standpoint: if there's a larger surface
area for potential corruption, then maybe it's wise to minimize that.
Well, no. Recursive functions /can/ be difficult to debug or validate.
They /can/ also be slower than their loopy counterparts. It is rare
that this is really important though and often times an algorithm is
just plain simpler in a recursive form.

Now, as to the general question. How would you alleviate the "problem"
of stack "depth" should you see such a problem? Well, the obvious
answer would be to pull all the functions you are calling up into their
caller so that instead of having a bunch of small, simple, easy to
manage functions you have one great big one. That's bad.

No, there is no need to pursue designs that minimize call depth...in
fact I would say they should be avoided in almost all, if not all,
situations.

Dec 8 '06 #6

"Noah Roberts" <ro**********@g mail.comwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
>
Tony wrote:
>"Gavin Deane" <de*********@ho tmail.comwrote in message
news:11******* *************** @16g2000cwy.goo glegroups.com.. .
>
Tony wrote:
Is there any value to pursuing program designs that mimimize
the mainline call stack?

That's a general question. As with any optimisation question, the
general answer is "no need".

I wasn't necessarily asking from an optimization standpoint. My concern
would be more from the robustness standpoint: if there's a larger surface
area for potential corruption, then maybe it's wise to minimize that.

Well, no. Recursive functions /can/ be difficult to debug or validate.
They /can/ also be slower than their loopy counterparts. It is rare
that this is really important though and often times an algorithm is
just plain simpler in a recursive form.

Now, as to the general question. How would you alleviate the "problem"
of stack "depth" should you see such a problem? Well, the obvious
answer would be to pull all the functions you are calling up into their
caller so that instead of having a bunch of small, simple, easy to
manage functions you have one great big one. That's bad.
I was only really concerned with the main() branch, pretty much like
my examples, rather than in general. I'm trying to come up with an entry
point mechanism other than main().
No, there is no need to pursue designs that minimize call depth...in
fact I would say they should be avoided in almost all, if not all,
situations.
Well that's some good news for someone considering dumping main()
then. :)

Tony
Dec 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1912
by: G Patel | last post by:
Can people please comment on the layout/style of my problem? The major issue I had was the layout. I ended up having to put a relatively large switch statement, inside an if statement, which is inside a while loop. If someone can tell me how I can rearrange these elements a little to make it cleaner, I would appreciate that. I've tested it...
22
7706
by: CK | last post by:
Hi EveryBody! This is the World Smallest Program in c. main(l ,a,n,d)char**a;{ for(d=atoi(a)/10*80- atoi(a)/5-596;n="@NKA\ CLCCGZAAQBEAADAFaISADJABBA^\ SNLGAQABDAXIMBAACTBATAHDBAN\ ZcEMMCCCCAAhEIJFAEAAABAfHJE\
13
25502
by: Ben R. Bolton | last post by:
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed. Is it possible to change the StackSize in .NET? If so how? Is it possible to determine the amount of memory used in the current stack? Any assistance would be appreciated. Ben
24
6556
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means the stack pointer should go upwards when there are "push" operations, and stack pointer should go downards when there are "pop" operations?? If...
6
2190
by: dspfun | last post by:
I would like to analyze my running c-program. What I would like to know for example is the range of the entire address space of my running c-program (memory reserved for/by the running program), starting address and sizes of text (code), stack, heap, bss, constant data, linked in libraries, etc. What are some good ways to extract this...
13
9669
by: Bob | last post by:
Hi, I have a newbie question. What is the smallest type object size? I am doing some calculation with individual bits and want to minimize memory usage. I though bool might do it but it seems like each bool is a byte, instead of a bit. Is bool the smallest possible type? Thanks, Bob
2
3029
by: PJ6 | last post by:
I have an algorithm that processes data recursively. When I'm testing it works fine, but when I feed it data from the actual application, I get "stack overflow". What bothers me is that the data my recursive processor is seeing in production is identical to the test data; the only difference is that now the processor must go deeper into an...
60
4821
by: harshal | last post by:
Hi all, Can we read the stack frame's of the current process. as we know that whenever a function call is made in c new functions stack frame is created and pushed on to the stack. and when the function returns it is popped out from the stack. i want to know the caller functions name. i mean i want something like this
4
4067
by: lianne.ribeiro | last post by:
I am using Visual C++ 6 IDE,with 512MB RAM. I have coded a recursive function that has a correct end condition for recursion. There is no infinite recursion. For some input data,the recursive function gets called so many times that it causes a 'First-chance exception in a.exe: 0xC00000FD: Stack Overflow.' How do i increase the size of...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.