my method to optimize application startup performance

This is a discussion on my method to optimize application startup performance within the C Programming forums, part of the General Programming Boards category; Hello everyone, I found that for an application, if I specify the entry point function (e.g. main), the performance of ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    my method to optimize application startup performance

    Hello everyone,


    I found that for an application, if I specify the entry point function (e.g. main), the performance of startup will be greatly improved.

    My questions are,

    1. If no entry point is specified, how will debugger of Visual Studio find the entry point function? Will the time to search entry point function long?

    For example, in my application, I defined the main function like this,

    int main(void)

    how will debugger treat main as the start point to execute (I set a break point to this function if I do not specify the entry point, then after a couple of minutes after pressing F5 to trigger debugger, debugger will jumps to main)?

    If I specify the entry point to main, then debugger will directly jumps to this function after F5 debugging.

    2. Specify entry point is a way to improve performance?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Huh? Can you explain what you mean? "main" is ALWAYS the entry point, but perhaps what you actually mean is that you tell the debugger to set a breakpoint at main, rather than run in debug mode all the way through the startup code, or some such?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by matsp View Post
    Huh? Can you explain what you mean? "main" is ALWAYS the entry point, but perhaps what you actually mean is that you tell the debugger to set a breakpoint at main, rather than run in debug mode all the way through the startup code, or some such?

    --
    Mats
    main() is *never* the entry point of a program. Before main is executed, a number of functions are called, such as functions that set up the stack, heap and so on, and also constructor functions, if you specified any.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by IceDane View Post
    main() is *never* the entry point of a program. Before main is executed, a number of functions are called, such as functions that set up the stack, heap and so on, and also constructor functions, if you specified any.
    OK, but main() is the default entry point as far as functions that you actually write. I've never seen a way (other than using assembly or compiler switches) to define those other things that get setup before main().

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    If you omit the main function, you'll get a linker error or compile error.
    Most likely linking error.
    Last edited by Elysia; 11-22-2007 at 11:42 AM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,308
    main() is *never* the entry point of a program. Before main is executed, a number of functions are called, such as functions that set up the stack, heap and so on, and also constructor functions, if you specified any.

    OK, but main() is the default entry point as far as functions that you actually write. I've never seen a way (other than using assembly or compiler switches) to define those other things that get setup before main().
    Perhaps we could avoid being pedantic and just say "the function called at program startup" instead of "the entry point function", since the former seems to be what George2 is referring to.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by laserlight View Post
    Perhaps we could avoid being pedantic and just say "the function called at program startup" instead of "the entry point function", since the former seems to be what George2 is referring to.
    I dislike the word "pedantic" - I prefer "detailed."

    Anyway, if you're not detailed, you can risk misinforming people. The function called at program start up could be a constructor, if you define a function in your program with the constructor attribute, and besides that, there are many functions called before main which are put in there by your compiler.

    I'd call it, "the function which stores your code," really, as that's pretty much what it is. Main is never the first or last function to be called.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Let's put it as the entry-point to your CODE and NOT your program, then?

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,308
    The function called at program start up could be a constructor, if you define a function in your program with the constructor attribute, and besides that, there are many functions called before main which are put in there by your compiler.
    Section 5.1.2 of C99 disagrees with respect to "function called at program start up", at least for a hosted environment:
    Two execution environments are defined: freestanding and hosted. In both cases, program startup occurs when a designated C function is called by the execution environment. All objects with static storage duration shall be initialized (set to their initial values) before program startup. The manner and timing of such initialization are otherwise unspecified. Program termination returns control to the execution environment.

    ... freestanding environment stuff ...

    A hosted environment need not be provided, but shall conform to the following specifications if present.

    The function called at program startup is named main.
    ... other stuff having to do with the definition of main in a hosted environment ...
    "Entry point" seems a little more ambiguous, but clearly if "all objects with static storage duration shall be initialized before program startup", program startup is not the entry point. That said, call it "pedantic" or "detailed" if you like, but all this context depends on what George2 is really asking, and I think he needs to clarify that.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by laserlight View Post
    Section 5.1.2 of C99 disagrees with respect to "function called at program start up", at least for a hosted environment:


    "Entry point" seems a little more ambiguous, but clearly if "all objects with static storage duration shall be initialized before program startup", program startup is not the entry point. That said, call it "pedantic" or "detailed" if you like, but all this context depends on what George2 is really asking, and I think he needs to clarify that.
    I agree that he needs to clarify, yes, but even so, what you quoted is ambiguous, too.

    "Program startup" doesn't necessarily mean "start of the executable code" - Just try loading an application compiled with your favorite compiler in a debugger and you'll see.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,308
    I agree that he needs to clarify, yes, but even so, what you quoted is ambiguous, too.
    I agree.

    "Program startup" doesn't necessarily mean "start of the executable code" - Just try loading an application compiled with your favorite compiler in a debugger and you'll see.
    From what I see, C99 does not explicitly define what "program startup" is, other than defining it terms of when it happens, i.e., when "a designated C function is called by the execution environment". Consequently, this is indeed ambiguous, but at least we have something that is standard terminology, as opposed to "the function which stores your code" (oh, you mean the "Save" function? ).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    So, you want to skip all that "useless" initialization of the environment and standard library and go straight to main(). Okay chief. Yeah. You're optimizing now.

  13. #13
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by brewbuck View Post
    So, you want to skip all that "useless" initialization of the environment and standard library and go straight to main(). Okay chief. Yeah. You're optimizing now.
    wonderful :-D

  14. #14
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'd be more concerned about performance after startup, since most programs spend a lot more time running than they do starting.

  15. #15
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by cpjust View Post
    I'd be more concerned about performance after startup, since most programs spend a lot more time running than they do starting.
    Quote Originally Posted by sloppy View Post
    wonderful :-D
    As cpjust said, your optimization will be pointless. I'm pretty sure that most (good) compilers optimize as much as they can without sacrificing anything necessary.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Application fails to load settings only at windows startup
    By DanFraser in forum C# Programming
    Replies: 3
    Last Post: 09-27-2009, 12:15 PM
  2. Optimize file writing
    By Opariti in forum Windows Programming
    Replies: 7
    Last Post: 10-23-2008, 02:32 PM
  3. Application.Exit
    By George2 in forum C# Programming
    Replies: 8
    Last Post: 05-02-2008, 03:24 AM
  4. Speed of C++
    By bobthebullet990 in forum A Brief History of Cprogramming.com
    Replies: 64
    Last Post: 01-12-2007, 02:39 AM
  5. Startup using STARTUP folder method for winXP & win98
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 05-26-2005, 05:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21