When unsafe is better PDF Print E-mail
Written by Daniel P   
Thursday, 22 June 2006

I rewrote Peter Warden's wave video effect in C#. My first attempt was a straigthforward cut at it and the result wasn't pretty. I managed to treat 45-48 frames out of a total of 292. I looked at the original C++ code and it treated 261-262 frames. So I used unsafe code and rewrote my code in C# but "in a C-style". The result was much better. 256-258 frames were treated with my newer version or within 1-3% of the C/C++ equivalent. In fact, unsafe code with pointers in C# reminds me a lot of the inline assembly feature of VC++, for example.

Then I searched Google and found an interesting collection of articles by Mr. Net Performance, Rico Mariani, which stated: "The managed code got a very good result for hardly any effort".




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
Portable code, .Net and C# PDF Print E-mail
Written by Daniel P   
Thursday, 15 June 2006

While working on my FreeFrame wrapper I encountered an interesting situation. The only function exported by the dll of a FreeFrame video effect has a signature that only uses "unsigned int" in order to ease portability. But this function is used to return (single precision) floating-point values (stored in an unsigned int). Unsigned integers in the .Net world are not CLS-compliant so I created a COM interface in which these functions return float values and I just make the translation in the COM component using the familiar C/C++ code:

float * fptr = (float *)&tmpResult; //tmpResult is unsigned int
*finalResult = *fptr;

Then I realized that I could use the same code with C# in an unsafe method. I tried and I checked that the assembly code for the C/C++ version and the C# version is identical (a "lea" instruction followed by a "mov"). Decidedly, we need C/C++ in fewer and fewer places.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 37 - 40 of 81
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design