Tuesday, July 14, 2009

How can I optimize a C++.NET DLL?

I've just finished creating a .NET Class Library DLL of a C++ Application I've been working on.





It mainly deals with graphics processing routines and the purpose of the DLL is so that I can use it with my primary application which is written in C#.





I've successfully added the DLL as a reference and I can call the functions but some of the routines that take 1 second to complete when run in standard C++ take nearly 50 seconds to complete when called from C# across the DLL.





I wrote a quick function to return a Bitmap loaded from file across the DLL and C# was able to get *this* done in a second, so I'm assuming it's my Bitmap filter routines that need optimizing.





Does anyone have some helpful tips on how I can re-do the DLL without major routines re-writes or optimize it so that the processing times are about the same as they conventionally are?





Thanks!

How can I optimize a C++.NET DLL?
So that i understand this correctly, you wrote a DLL in C++ and are referencing it from C#...Makes sense....And you mention that that DLL, when it takes action, normally thakes 1 second to process a loaded bitmap (using your filter routine) but when you call that same C++ function(s) from your C# app then the result takes 50+ secs?





And you've narrowed it down to not be the problem of the Bitmap loading (either from C++ or C#) but potentially the Bitmap filtering routines held in the C++ DLL when being requested from C#?





Not sure if you would want to do this but have you tried inlining the C++ unmanaged code routines within your C# app and see if that helps (C# can execute C++ code too -- in unmanaged mode, of course).





It is a bit strange to me why your routines take 50+ seconds when being requested from C# because i've done some very intense graphical stuff in the same manner (C# to C++ dll) and have not experienced this before. Granted the DLL and its dependent libraries are not loaded at runtime until required by the C# code and so when you make your requests it is technically then starting to put your code into memory and process it (and its supporting libraries) -- this is possibly the slow down...You could have it loaded immediately into your process space when your c# code launches


No comments:

Post a Comment