Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VladTheImpaler
    wrote on last edited by
    #1

    [Message Deleted]

    T J 2 Replies Last reply
    0
    • V VladTheImpaler

      [Message Deleted]

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Is exiting the function right away will provide less memory movement Don't worry about that. Worry about code readability - and in this case exiting early wins hands down. Tomasz Sowinski -- http://www.shooltz.com

      1 Reply Last reply
      0
      • V VladTheImpaler

        [Message Deleted]

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        Chances are it makes no difference which version you use, as probably the compiler redirects all returns inside a function to the same code stub. Anyway, you can always try to run a profile batch against your program to know (your VC++ comes with a profiler tool). From the point of view of readability, my opinion is (in accordance with what others have said) that the first version is better: When you finally got to the main part of code all secondary scenarios are ruled out, and that makes it easier to concentrate on a smaller mental model of your problem. That's how my brain works at least. I guess this could make for an interesting discussion subject at the lounge. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        V 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          Chances are it makes no difference which version you use, as probably the compiler redirects all returns inside a function to the same code stub. Anyway, you can always try to run a profile batch against your program to know (your VC++ comes with a profiler tool). From the point of view of readability, my opinion is (in accordance with what others have said) that the first version is better: When you finally got to the main part of code all secondary scenarios are ruled out, and that makes it easier to concentrate on a smaller mental model of your problem. That's how my brain works at least. I guess this could make for an interesting discussion subject at the lounge. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          V Offline
          V Offline
          VladTheImpaler
          wrote on last edited by
          #4

          [Message Deleted]

          T 1 Reply Last reply
          0
          • V VladTheImpaler

            [Message Deleted]

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #5

            second option generates a higher jump value than the first one So what? How many nanoseconds do you want to save? I think you're wasting your time on totally irrelevant stuff. Tomasz Sowinski -- http://www.shooltz.com

            V 1 Reply Last reply
            0
            • T Tomasz Sowinski

              second option generates a higher jump value than the first one So what? How many nanoseconds do you want to save? I think you're wasting your time on totally irrelevant stuff. Tomasz Sowinski -- http://www.shooltz.com

              V Offline
              V Offline
              VladTheImpaler
              wrote on last edited by
              #6

              [Message Deleted]

              T 1 Reply Last reply
              0
              • V VladTheImpaler

                [Message Deleted]

                T Offline
                T Offline
                Tomasz Sowinski
                wrote on last edited by
                #7

                In a 3d engine, nothing is Irrelevant when it's about optimization Bullshit. In function like this you're checking if file exists. This means you have to call underlying OS, which usually causes context switch. This operation alone takes orders of magnitude longer than time saved with possible 'optimization' after rearranging control flow. As Michael Abrash writes in his "Graphics Programming Black Book": Know when it matters. (identify the portions of your program where peformance matters, and don't waste your time optimizing the rest. Tomasz Sowinski -- http://www.shooltz.com

                V 1 Reply Last reply
                0
                • T Tomasz Sowinski

                  In a 3d engine, nothing is Irrelevant when it's about optimization Bullshit. In function like this you're checking if file exists. This means you have to call underlying OS, which usually causes context switch. This operation alone takes orders of magnitude longer than time saved with possible 'optimization' after rearranging control flow. As Michael Abrash writes in his "Graphics Programming Black Book": Know when it matters. (identify the portions of your program where peformance matters, and don't waste your time optimizing the rest. Tomasz Sowinski -- http://www.shooltz.com

                  V Offline
                  V Offline
                  VladTheImpaler
                  wrote on last edited by
                  #8

                  [Message Deleted]

                  T 1 Reply Last reply
                  0
                  • V VladTheImpaler

                    [Message Deleted]

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #9

                    But let say this function is called every cycle Are we still talking about bmpLoader function? Do you suggest that you'll be loading bitmaps from disk in tight, time-critical loop? Tomasz Sowinski -- http://www.shooltz.com

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups