C# speed vs unmanaged C++
-
My app has to render a bitmap by scanning a FP measurement array, using a lookup table type process. In the old C++/MFC app that does more or less the same thing, the rendering runs very noticably faster using the same camera and image size, on the same PC. In C#, I was using the SetPixel command, but this is still as slow as the infamous GDI SetPixel call. Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow. So my questions are these. 1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar. 2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer. Thanks for any ideas. Stewart DIBBS
-
My app has to render a bitmap by scanning a FP measurement array, using a lookup table type process. In the old C++/MFC app that does more or less the same thing, the rendering runs very noticably faster using the same camera and image size, on the same PC. In C#, I was using the SetPixel command, but this is still as slow as the infamous GDI SetPixel call. Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow. So my questions are these. 1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar. 2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer. Thanks for any ideas. Stewart DIBBS
sjdevo3gsr wrote:
- Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar.
Yes, in this case. Native pointer math is always faster for bitmaps, all other things being equal. If you're doing a lot of memory access and you're sure your not going to overrun any buffers or anything, unmanaged code can be blazingly faster for bitmap work. You may also have easier access to BitBlt and similar functions, which could save you a lot of math.
sjdevo3gsr wrote:
- Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer.
You can put managed C++ classes in your C# project/solution. They're still managed, though. That may not necessarily be bad. You can also but "unsafe" C# code inline in your C# files. That will allow you to use pointers. It's not going to be as fast as native Win32 C code, but it'll allow pointer math, which could save you time over ordinary C# code in this case.
-
My app has to render a bitmap by scanning a FP measurement array, using a lookup table type process. In the old C++/MFC app that does more or less the same thing, the rendering runs very noticably faster using the same camera and image size, on the same PC. In C#, I was using the SetPixel command, but this is still as slow as the infamous GDI SetPixel call. Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow. So my questions are these. 1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar. 2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer. Thanks for any ideas. Stewart DIBBS
From doing experiments with encryption (Blowfish) in both C# and mixed mode C/C++. The native code performs about 4 times faster (12MB/s vs 50MB/s throughput). Use MC++ to mixed a little managed code with native code. There are ways to embed it, but it's a difficult process (not suggested). Have a look at the link below if you are interested. http://blogs.msdn.com/junfeng/archive/2006/05/20/599434.aspx[^]**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
My app has to render a bitmap by scanning a FP measurement array, using a lookup table type process. In the old C++/MFC app that does more or less the same thing, the rendering runs very noticably faster using the same camera and image size, on the same PC. In C#, I was using the SetPixel command, but this is still as slow as the infamous GDI SetPixel call. Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow. So my questions are these. 1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar. 2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer. Thanks for any ideas. Stewart DIBBS
sjdevo3gsr wrote:
Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow.
Have you rechecked if you really used the whole potential of this method? My measurements when I once met this problem where that the difference was factor 5 or more...
-
sjdevo3gsr wrote:
Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow.
Have you rechecked if you really used the whole potential of this method? My measurements when I once met this problem where that the difference was factor 5 or more...