Why adding C++ Dll to C# project provides better performance

Why adding C++ Dll to C# project provides better performance

Postby pdshahv » Wed Sep 22, 2010 8:31 am

My company is working on implementing algorithmic stratigies and have a c# .net trading system working. However recently we are planning to go for numerical intensive stratigies for complex trading. However i have found that integrating c++ numercal intensive code in c++ as dll under c# wrapper will provide better performance.

However i am still not sure if integrating c++ dll to c# solution will really improve the performance as the execution will still be in .net environment so how will it be faster than c# ??
pdshahv
 
Posts: 1
Joined: Sun Sep 19, 2010 9:09 am

Postby robert2098 » Fri Sep 24, 2010 3:31 pm

If you call a ?native? .dll from .NET then the code from the .dll is not executed by the .NET JIT, but run directly. Thus code inside the native .dll should run just as fast if it was executed from a non .NET application. Only marshaling the data between .NET and the native .dll costs more time since data has to be converted. So keep the communication between .NET and native .dll at a minimum.



Some reasons why C++ code in a dll runs faster than .NET code is that C++ code runs without bounds checking and other safety checks. And also explicit memory management (new/delete) is faster than a garbage collector.



Since code in the native .dll runs outside the .NET framework, its execution can not be controlled/checked by .NET and might be a security risk when the .dll contains misbehaving code. Therefore, when your .NET program accesses a native .dll, your code is also marked as unsafe and can?t be executed anymore if the .NET program is started with lower permission (e.g. when downloaded and run from the internet).



Robert
robert2098
 
Posts: 2
Joined: Thu Dec 27, 2007 3:12 pm


Return to C++

Who is online

Users browsing this forum: No registered users and 1 guest

cron