So you want to write an image processing program in C#, do you? Why on earth would you want to do that? I can only think of a few reasons why that would be a good idea:
1) The existing codebase is in C#, and the idea of mixing languages with something more appropriate makes your head ache.
2) You're starting from scratch, and C# is new and shiny and everyone must love it.
3) Your boss told you to.
4) The voices in your head told you to.
Some of these reasons are valid, and some are not. Let's assume, for the sake of argument, that they are valid, and for whatever reason, you're forced to use C#. Some things you should know:
1) C# is slow. Yes, yes, there are claims (such as these) that C# is as fast, or faster. I must tell you, that for the purposes of running image processing applications, C# is slower than C# by a good long margin. In a later post, I'll talk about how much slower, but were talking 200ms for C++ vs 350 ms for C# for a particular algorithm on a 100x100 image. Scale that to a 9 megapixel 16 bit image, and you're looking at a very significant speed difference.
2) C# can be sped up, but usually through unsafe code. Unsafe code means that you lose a lot of what is good about the environment, like run-time checking of almost every error, and really nice debugging tools. C++ used to be unsafe, and we could edit that code on the fly while debugging, but you can no longer edit unsafe code on the fly in Visual Studio 2005. A shame, really, as it will reduce you to stopping and recompiling each time you make a change.
3) C# has a very different object model than C/C++/Java. C and C++ have C# struct type objects, Java has C# reference type objects, and if you don't know the difference, you could get burned really badly.
4) C# does have automatic garbage collection. However, that automatic garbage collection can be really slow when you're making multiple copies of a 9 megapixel 16 bit image, or if you're converting the image to floats or (god forbid) doubles for some interesting math (FFTW, anyone?). Get used to calling GC.Collect() and GC.WaitForPendingNotifiers() a lot.
There's plenty of other things that I've learned while making an image processing application in C#, and these are just the beginning. As I go through the things I've learned, I'll post them here, so that other people won't have to suffer (as much) as I did, or at least, that's the hope.
mmr
Wednesday, July 25, 2007
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment