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. COM
  4. Speed difference between CoCreateInstance and new operator

Speed difference between CoCreateInstance and new operator

Scheduled Pinned Locked Moved COM
comperformancequestion
12 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.
  • A Alexandre GRANVAUD

    Hi guys, I have COM DLL Servers creating a lot of COM objects with CoCreateInstance and it's quite slow. I wondered if replacing the CoCreateInstance(CLSID_Foo) by a new CComObject < CFoo > would speed up things ? Or to be clearer, how slower is CoCreateInstance compared to new operator ? thanks !

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #3

    You simply cannot use new to create COM objects (COM objects lifetime has its own rules :rolleyes: ). If you need to create multiple objects, then you may obtain a speed enhancement using directly the IClassFactory interface, see the remarks section of this page [^].

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    In testa che avete, signor di Ceprano?

    A 1 Reply Last reply
    0
    • R Roger Stoltz

      Alexandre GRANVAUD wrote:

      I wondered if replacing the CoCreateInstance(CLSID_Foo) by a new CComObject < CFoo > would speed up things ?

      No. Since in both ways a COM object is created. Using the "new operator", as you call it, will eventually call ::CoCreateInstance(), so there's no difference.

      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      A Offline
      A Offline
      Alexandre GRANVAUD
      wrote on last edited by
      #4

      calling new CComObject < CThing > calls CoCoreateInstance???? i'm sure it doesnt !!

      R 1 Reply Last reply
      0
      • CPalliniC CPallini

        You simply cannot use new to create COM objects (COM objects lifetime has its own rules :rolleyes: ). If you need to create multiple objects, then you may obtain a speed enhancement using directly the IClassFactory interface, see the remarks section of this page [^].

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        A Offline
        A Offline
        Alexandre GRANVAUD
        wrote on last edited by
        #5

        yes you can in the same DLL, i do it everyday : in inprocess it's ok to do so ;) new CComObject < CThing > then doing a Queryinterface or a AddRef on it and your object is ok

        CPalliniC 1 Reply Last reply
        0
        • A Alexandre GRANVAUD

          calling new CComObject < CThing > calls CoCoreateInstance???? i'm sure it doesnt !!

          R Offline
          R Offline
          Roger Stoltz
          wrote on last edited by
          #6

          Alexandre GRANVAUD wrote:

          calling new CComObject < CThing > calls CoCoreateInstance???? i'm sure it doesnt !!

          No, of course; allocating memory for a CComObject doesn't call ::CoCreateInstance(). But in order to create the server you'd have to call CComObject::CreateInstance(). Otherwise the server won't be created and your comparison wouldn't make sense at all. :suss:

          "It's supposed to be hard, otherwise anybody could do it!" - selfquote
          "High speed never compensates for wrong direction!" - unknown

          A 1 Reply Last reply
          0
          • R Roger Stoltz

            Alexandre GRANVAUD wrote:

            calling new CComObject < CThing > calls CoCoreateInstance???? i'm sure it doesnt !!

            No, of course; allocating memory for a CComObject doesn't call ::CoCreateInstance(). But in order to create the server you'd have to call CComObject::CreateInstance(). Otherwise the server won't be created and your comparison wouldn't make sense at all. :suss:

            "It's supposed to be hard, otherwise anybody could do it!" - selfquote
            "High speed never compensates for wrong direction!" - unknown

            A Offline
            A Offline
            Alexandre GRANVAUD
            wrote on last edited by
            #7

            why do you need to call it ? as i can see, the CCOmObject constructor call FinalConstruct, so what extra initialization do we need ?

            1 Reply Last reply
            0
            • A Alexandre GRANVAUD

              yes you can in the same DLL, i do it everyday : in inprocess it's ok to do so ;) new CComObject < CThing > then doing a Queryinterface or a AddRef on it and your object is ok

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #8

              And what is the rationale behind that (other than revealing your bad practices :rolleyes:)?

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              A 1 Reply Last reply
              0
              • CPalliniC CPallini

                And what is the rationale behind that (other than revealing your bad practices :rolleyes:)?

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                A Offline
                A Offline
                Alexandre GRANVAUD
                wrote on last edited by
                #9

                speed is always a good practice ;) having a bad practice is ok if you know you have (i do ;)) and know the consequences ;)

                CPalliniC 1 Reply Last reply
                0
                • A Alexandre GRANVAUD

                  speed is always a good practice ;) having a bad practice is ok if you know you have (i do ;)) and know the consequences ;)

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #10

                  Alexandre GRANVAUD wrote:

                  speed is always a good practice

                  Before the first road accident ;P --Carlo The Motor Biker. (Anyway Carlo The Developer suspects it is more coding lazyness than speed improvement... :rolleyes:). BTW breaking the COM object creation mechanism is really a bad practice and even if you're stuck with it, please don't tell other people to do it. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  A 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    Alexandre GRANVAUD wrote:

                    speed is always a good practice

                    Before the first road accident ;P --Carlo The Motor Biker. (Anyway Carlo The Developer suspects it is more coding lazyness than speed improvement... :rolleyes:). BTW breaking the COM object creation mechanism is really a bad practice and even if you're stuck with it, please don't tell other people to do it. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    A Offline
                    A Offline
                    Alexandre GRANVAUD
                    wrote on last edited by
                    #11

                    lol i agree for the speed ;) (but can't slowdown) i don't break the com creation mechanism : the CreateInstance in a ClassFactory does exactly the same : a new CComObject ! ;)

                    CPalliniC 1 Reply Last reply
                    0
                    • A Alexandre GRANVAUD

                      lol i agree for the speed ;) (but can't slowdown) i don't break the com creation mechanism : the CreateInstance in a ClassFactory does exactly the same : a new CComObject ! ;)

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #12

                      Alexandre GRANVAUD wrote:

                      i don't break the com creation mechanism : the CreateInstance in a ClassFactory does exactly the same : a new CComObject !

                      Avoiding such call you're breaking it by definition. Of course you'll see the practical implications of such a wicked act just on 'strange' servers (i.e. servers that don't "do exactly the same", such a behaviour is allowed by COM). :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      In testa che avete, signor di Ceprano?

                      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