Compile and execute problem

This is a discussion on Compile and execute problem within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have a run-time problem with my application. When I first turn on my PC, compile my application and ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    145

    Compile and execute problem

    Hello,

    I have a run-time problem with my application. When I first turn on my PC, compile my application and execute it, it takes around 20 to 30 to "get ready". It is the process of start-up what consumes so much time.

    My problem comes when I compile again the executable, or if I modify something to try it and compile it to test it. The second and sucessive times I compile and executes the application it takes only 2-3 seconds to load and be ready. Then, if I reboot and executes it again, that just compiled version which took only 2 or 3 seconds now takes 20 to 30.

    As I see it, it looks like an OS paging which help to speed up the start process. I suspect same sections of the executable remain in virtual memory so next executions take less time.

    Is there any way I can force my app or the os to load the app like the first time?, or unload cached sections? it is important for me because I look for programmatic ways to improve that first costly startup time, and it is difficult as it is now because I can not profile corretly the time.

    I am using Windows-XP, but I have seen the same problem in Vista.

    Best regards.
    Fermin

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    This is typically because there is a lot of stuff to load from your hard drive, which takes a lot of time. But when loading things, it gets cached in the cpu cache (and memory to some degree), so the next time you restart it, it loads directly from the cache. This is OS independent.
    Solve it? Yeah, there are a couple of ways.
    One is just to load everything up and ignore the results. This warms up the cache. The next time you do it, it will be fast.
    The second way is to just get an SSD. Trust me, it helps. A lot.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    The time you are mentioning is most likely the compile process, not the startup. Test your program out of the IDE to verify this.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    145
    Quote Originally Posted by nvoigt View Post
    The time you are mentioning is most likely the compile process, not the startup. Test your program out of the IDE to verify this.
    Not. I have tested it outside IDE and the problems continues.

    My program open and used data files at opening that seem to be cached. That is the problem. I would like to improve this start up routine so any person trying the program for first time get a reasonable fast startup. But this is annoyed, I can't improve that routine if the system caches what I need not to be cached.
    My users are only execute the application from time to time, so cache is not an option, I need to improve the load process, maybe using files in other way, or trying to improving routines, but need to test it....

    to @elysa: I dont understand your solution of use a SSD, could you elaborate it, please?

    thanks

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    There is only one solution that you can use, and that is to cache all the data you need at start. Read in whatever data you need (if it isn't too much) and keep it around until you need it. This is hit and miss, though, depending on many factors.

    Outside of this, there is really nothing you can do. The users of your programs must configure their system to make it faster. They could, for example, open the program slightly after startup just to keep it cached. Or they could upgrade their system to make it faster.

    If you want detailed help on possible optimizations, you have to provide your code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    I have the same problem, but less severe - more like 5-10 secs for me. I've never really thought about it before.

    You should try to identify what is causing the slowness (almost certainly non cached disk I/O, but loading what?). I just had a quick play with Process Monitor on an application of mine that always starts slowly. I traced a cold slow startup and a couple of quick runs.

    I didn't find anything very surprising -- pretty much all the extra time was used reading uncached data (DLLs and data files) from disk. Subsequent runs accessed the same data but much faster and in much fewer calls to ReadFile (more bytes transferred in each call).

    Seems pretty clearly cache related.

    One approach is to try to get everything loaded ASAP as suggested, perhaps just after system startup time. You could be an evil app writer and have a background process that just sits around reloading your stuff into the cache every now and then. But it sounds like you, like me, have no severe problems once it's been run once. If it's taking time actually loading the program code, you could try having the compiler non critical files for code size rather than speed.

    As well, you should find out if there's anything happening at application start time that could be postponed until later. E.g. if you're reading in loads of files, could you read them on demand? Any DLLs that could be lazily loaded?
    If you can postpone some of the I/O then the slowdown might be gracefully absorbed by the rest of the program.
    (I think Window's Prefetching only monitors executables for 10 seconds after they start though, so this might offset any gain).
    There might not be much you can do as presumably the time is taken before your code even starts running - but worth a look.

    Let us know if you find anything interesting!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with c++ error n dont execute [W7 64xbit]
    By slambergamer in forum C++ Programming
    Replies: 27
    Last Post: 12-17-2010, 11:19 PM
  2. Compile Problem - Dev C++
    By Jack_Zepp in forum C Programming
    Replies: 4
    Last Post: 07-22-2010, 08:26 AM
  3. compile problem
    By eriaug in forum C++ Programming
    Replies: 6
    Last Post: 12-12-2004, 11:47 AM
  4. Execute Problem
    By Marc Sharp in forum C Programming
    Replies: 4
    Last Post: 11-22-2003, 01:25 AM
  5. gcc compile problem
    By keyz in forum Linux Programming
    Replies: 3
    Last Post: 05-22-2003, 07:14 AM

Tags for this Thread


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