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. Template - code bloat ?!!

Template - code bloat ?!!

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpfgraphicsquestion
5 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.
  • R Offline
    R Offline
    Ravish
    wrote on last edited by
    #1

    I am new to templates in C++. Say I have declared Vector in first.cpp and also in Second.cpp. Does the compiler generate two Vector implementation ?. If so is there any way I can force the compiler to generate just a single implementation. Thanks

    J C 2 Replies Last reply
    0
    • R Ravish

      I am new to templates in C++. Say I have declared Vector in first.cpp and also in Second.cpp. Does the compiler generate two Vector implementation ?. If so is there any way I can force the compiler to generate just a single implementation. Thanks

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

      It is the linker's responsibility to strip off duplicates across compilation units, so in general there'll be only one implementation. Code bloat can stem from another reasons:

      • instantiating vectors (or other template classes) of many different types
      • code bloat resulting from massive inlining

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      C 1 Reply Last reply
      0
      • C Christian Graus

        It works exactly the same as if you had two instances of a non-templated class. The template code bloat is that the compiler needs to generate new classes for each DIFFERENT template parameter it is used with. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

        R Offline
        R Offline
        Ravish
        wrote on last edited by
        #3

        Thanks

        1 Reply Last reply
        0
        • R Ravish

          I am new to templates in C++. Say I have declared Vector in first.cpp and also in Second.cpp. Does the compiler generate two Vector implementation ?. If so is there any way I can force the compiler to generate just a single implementation. Thanks

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It works exactly the same as if you had two instances of a non-templated class. The template code bloat is that the compiler needs to generate new classes for each DIFFERENT template parameter it is used with. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

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

            It is the linker's responsibility to strip off duplicates across compilation units, so in general there'll be only one implementation. Code bloat can stem from another reasons:

            • instantiating vectors (or other template classes) of many different types
            • code bloat resulting from massive inlining

            Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Joaquín M López Muñoz wrote: code bloat resulting from massive inlining Although I'll point out that inline is a suggestion to the compiler, not a command. If you inline stupidly, the compiler will ignore you. Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001 Picture the daffodil. And while you do that, I'll be over here going through your stuff.

            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