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. C++ vs. C#

C++ vs. C#

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++visual-studio
10 Posts 4 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.
  • P Offline
    P Offline
    PankajB
    wrote on last edited by
    #1

    Hi All. I have a simple question... Lets say I have a C++ DLL with one exposed fucntion. Now, If this fucntion get called from C++ Source code OR from C# Source code, then do we any difference on the basis of calling language, as far as performace of this DLL[exposed function] is concerned? In case you need any further information, please let me know. Thanks PanB

    R J 2 Replies Last reply
    0
    • P PankajB

      Hi All. I have a simple question... Lets say I have a C++ DLL with one exposed fucntion. Now, If this fucntion get called from C++ Source code OR from C# Source code, then do we any difference on the basis of calling language, as far as performace of this DLL[exposed function] is concerned? In case you need any further information, please let me know. Thanks PanB

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Your question is unclear.

      It is a crappy thing, but it's life -^ Carlo Pallini

      P 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        Your question is unclear.

        It is a crappy thing, but it's life -^ Carlo Pallini

        P Offline
        P Offline
        PankajB
        wrote on last edited by
        #3

        Ok. Lets say I have a Win32 C++ DLL and there is an exposed function Calculation(). Now if I call this function from C++ Source Code OR if I call this from C# Source code, then will there be any performance issue, as far as function Calculation() is concerned? Thanks.

        R 1 Reply Last reply
        0
        • P PankajB

          Ok. Lets say I have a Win32 C++ DLL and there is an exposed function Calculation(). Now if I call this function from C++ Source Code OR if I call this from C# Source code, then will there be any performance issue, as far as function Calculation() is concerned? Thanks.

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          What does your profiling test results say?

          It is a crappy thing, but it's life -^ Carlo Pallini

          P 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            What does your profiling test results say?

            It is a crappy thing, but it's life -^ Carlo Pallini

            P Offline
            P Offline
            PankajB
            wrote on last edited by
            #5

            I have not done any profiling OR I even dont have any setup like that. Just want to have a view from other side? As per my understanding there should not be any difference in terms of performance. What do you say?

            L 1 Reply Last reply
            0
            • P PankajB

              I have not done any profiling OR I even dont have any setup like that. Just want to have a view from other side? As per my understanding there should not be any difference in terms of performance. What do you say?

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

              IIRC it depends on the number and type of parameters you pass to it and the return value. Short functions have significant overhead, especially if they have string arguments. Why didn't you just test it though?

              PankajB wrote:

              I have not done any profiling OR I even dont have any setup like that.

              So which is it?

              P 1 Reply Last reply
              0
              • L Lost User

                IIRC it depends on the number and type of parameters you pass to it and the return value. Short functions have significant overhead, especially if they have string arguments. Why didn't you just test it though?

                PankajB wrote:

                I have not done any profiling OR I even dont have any setup like that.

                So which is it?

                P Offline
                P Offline
                PankajB
                wrote on last edited by
                #7

                It seems that you did'nt get me. Case 1: Win32 DLL is being used by C++ application. Called an exposed function, lets say ABC(). Case 2: Same Win32 DLL is being used now by C# application. Called an exposed function, lets say ABC(). [Previous C++ Application closed. Both of these callings C++/C# are independent to each other]

                R L 2 Replies Last reply
                0
                • P PankajB

                  It seems that you did'nt get me. Case 1: Win32 DLL is being used by C++ application. Called an exposed function, lets say ABC(). Case 2: Same Win32 DLL is being used now by C# application. Called an exposed function, lets say ABC(). [Previous C++ Application closed. Both of these callings C++/C# are independent to each other]

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  Managed code is slower than native, but just for calling a function in a library, I don't think there should be any difference as such. Further more, if you are talking about the execution time of the function within the DLL, that should remain the same (within the DLL), no matter what environment are you executing it from. I recommend that you do a little profiling and test it out. You don't need any setup as such. VS 2008 has profiling features inbuilt, or you could use a high resolution counter to find out how long has the function taken to execute from within the test environment (native or managed).

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  1 Reply Last reply
                  0
                  • P PankajB

                    It seems that you did'nt get me. Case 1: Win32 DLL is being used by C++ application. Called an exposed function, lets say ABC(). Case 2: Same Win32 DLL is being used now by C# application. Called an exposed function, lets say ABC(). [Previous C++ Application closed. Both of these callings C++/C# are independent to each other]

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

                    I did get you. Case 1: nothing to see here, normal case. Case 2: even if the C++ application was still running, it has nothing to do with it. Nothing. Why did you even bring it up? Anyway, a call from C# to a native function requires marshaling of the arguments and the return value (if it returns), which is obviously slower than not marshaling. The amount of marshaling is (equally obviously) dependent on the number of arguments and their type (so for some types, also of their size) edit: oh and IIRC the .NET runtime also does some safety checks with regards to the stack, but I don't know what it checks

                    1 Reply Last reply
                    0
                    • P PankajB

                      Hi All. I have a simple question... Lets say I have a C++ DLL with one exposed fucntion. Now, If this fucntion get called from C++ Source code OR from C# Source code, then do we any difference on the basis of calling language, as far as performace of this DLL[exposed function] is concerned? In case you need any further information, please let me know. Thanks PanB

                      J Offline
                      J Offline
                      Joe Woodbury
                      wrote on last edited by
                      #10

                      The native DLL is compiled. In theory, the functions within it will have the same performance regardless of what program is calling it, be it C++, C#, VBA, etc.. The theory falls down once you look at the program in question as a whole. Due to paging, the memory cache, pipelining issues, how the call is made (i.e interop) and so forth, the actual performance in real world conditions may vary.

                      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