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. Design and Architecture
  4. To Link or Not To Link? (Question of Efficiency)

To Link or Not To Link? (Question of Efficiency)

Scheduled Pinned Locked Moved Design and Architecture
helpquestionjsonlounge
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.
  • X Offline
    X Offline
    Xpnctoc
    wrote on last edited by
    #1

    General architectural question: From what I've been able to gather, there are basically 3 approaches to handling code that is reusable across multiple projects: 1. Dynamic linking: build a DLL, use API functions like LoadLibrary() and GetProcAddress() to link to the desired functionality at run time. 2. Static linking: build a DLL, use a .lib file to establish the external proc addresses at compile time. 3. Static library: build a LIB only, use as input that becomes part of the .exe file for a given project. It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it. But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general? What about in high-demand applications such as video games or real-time simulators, or where the library function is expected to be called dozens of times per second? Thanks for your help.

    L J 3 Replies Last reply
    0
    • X Xpnctoc

      General architectural question: From what I've been able to gather, there are basically 3 approaches to handling code that is reusable across multiple projects: 1. Dynamic linking: build a DLL, use API functions like LoadLibrary() and GetProcAddress() to link to the desired functionality at run time. 2. Static linking: build a DLL, use a .lib file to establish the external proc addresses at compile time. 3. Static library: build a LIB only, use as input that becomes part of the .exe file for a given project. It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it. But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general? What about in high-demand applications such as video games or real-time simulators, or where the library function is expected to be called dozens of times per second? Thanks for your help.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think that in performance terms there is very little to choose between 2 and 3. The trade-off comes when you have lots of apps running in your machine - using a DLL you have only one copy of each library function in memory, with the static library you have one copy for each app.

      Unrequited desire is character building. OriginalGriff

      X 1 Reply Last reply
      0
      • X Xpnctoc

        General architectural question: From what I've been able to gather, there are basically 3 approaches to handling code that is reusable across multiple projects: 1. Dynamic linking: build a DLL, use API functions like LoadLibrary() and GetProcAddress() to link to the desired functionality at run time. 2. Static linking: build a DLL, use a .lib file to establish the external proc addresses at compile time. 3. Static library: build a LIB only, use as input that becomes part of the .exe file for a given project. It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it. But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general? What about in high-demand applications such as video games or real-time simulators, or where the library function is expected to be called dozens of times per second? Thanks for your help.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Xpnctoc wrote:

        It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it.

        Without a context that is meaningless. For starters .Net and Java always do dynamic loads. Second performance is impacted much more significantly by requirements, architecture and design for most business applications. Third some business required functionality cannot be implemented with dynamic loads. For example hotloads of a 24x7 server.

        X 1 Reply Last reply
        0
        • X Xpnctoc

          General architectural question: From what I've been able to gather, there are basically 3 approaches to handling code that is reusable across multiple projects: 1. Dynamic linking: build a DLL, use API functions like LoadLibrary() and GetProcAddress() to link to the desired functionality at run time. 2. Static linking: build a DLL, use a .lib file to establish the external proc addresses at compile time. 3. Static library: build a LIB only, use as input that becomes part of the .exe file for a given project. It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it. But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general? What about in high-demand applications such as video games or real-time simulators, or where the library function is expected to be called dozens of times per second? Thanks for your help.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Xpnctoc wrote:

          It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it.

          During initialization, one creates a method-pointer, say, a delegate. During execution, you fire it. Can be pretty darn fast.

          Xpnctoc wrote:

          But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general?

          If your requirements require such speed, you'd be best of in using QNX[^].

          Bastard Programmer from Hell :suss:

          X 1 Reply Last reply
          0
          • J jschell

            Xpnctoc wrote:

            It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it.

            Without a context that is meaningless. For starters .Net and Java always do dynamic loads. Second performance is impacted much more significantly by requirements, architecture and design for most business applications. Third some business required functionality cannot be implemented with dynamic loads. For example hotloads of a 24x7 server.

            X Offline
            X Offline
            Xpnctoc
            wrote on last edited by
            #5

            Well I guess I could have been a little clearer, but since, as you said, .NET and Java always do dynamic loads, that's obviously not what I'm talking about. I'm talking about plain old C++. I also did specifically mention video games and real-time simulations.

            J 1 Reply Last reply
            0
            • L Lost User

              Xpnctoc wrote:

              It seems pretty obvious that #1 would represent the worst execution time because of the need to look up a proc address before calling it.

              During initialization, one creates a method-pointer, say, a delegate. During execution, you fire it. Can be pretty darn fast.

              Xpnctoc wrote:

              But the issue seems a little more fuzzy between #2 and #3. Is there a significant advantage to one over the other in general?

              If your requirements require such speed, you'd be best of in using QNX[^].

              Bastard Programmer from Hell :suss:

              X Offline
              X Offline
              Xpnctoc
              wrote on last edited by
              #6

              I thought about using function pointers. But then the sheer number of them I would need to generate and maintain at application start-up seems like it would be more work that it's worth. Might as well just stick with static linking or a static library.

              1 Reply Last reply
              0
              • L Lost User

                I think that in performance terms there is very little to choose between 2 and 3. The trade-off comes when you have lots of apps running in your machine - using a DLL you have only one copy of each library function in memory, with the static library you have one copy for each app.

                Unrequited desire is character building. OriginalGriff

                X Offline
                X Offline
                Xpnctoc
                wrote on last edited by
                #7

                That's kind of what I thought. Does having a larger executable result in slower app launch time? When exactly to statically linked DLLs get loaded -- on application start, first call, etc...?

                L 1 Reply Last reply
                0
                • X Xpnctoc

                  That's kind of what I thought. Does having a larger executable result in slower app launch time? When exactly to statically linked DLLs get loaded -- on application start, first call, etc...?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Xpnctoc wrote:

                  Does having a larger executable result in slower app launch time?

                  Probably, but unless you are loading and unloading thousands of times a minute it is unlikely to be an issue.

                  Xpnctoc wrote:

                  When exactly to statically linked DLLs get loaded

                  On first call as far as I am aware.

                  Unrequited desire is character building. OriginalGriff

                  1 Reply Last reply
                  0
                  • X Xpnctoc

                    Well I guess I could have been a little clearer, but since, as you said, .NET and Java always do dynamic loads, that's obviously not what I'm talking about. I'm talking about plain old C++. I also did specifically mention video games and real-time simulations.

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #9

                    Xpnctoc wrote:

                    I also did specifically mention video games and real-time simulations.

                    amic calls. Could be mistaken though. Presumably you are familiar with 'video drivers' on PCs? The things that directly drive all the video on the box. They are pluggable components in the OS.

                    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