Migrating from C# to C++, and from Windows.Forms to wxWidgets

Posted on:May 01 2006

During the last 4 weeks, I started to write a small 3D editor. I started it in C#, using Irrlicht.NET and Windows.Forms for the UI. But three days ago, I decided that it would be better to stop development and restart it with C++ and wxWidgets, before it would be too advanced. The main reason behind this decision was that it would be simpler to improve Irrlicht simultaneous with the Editor, and easier to try out different approaches to new features, because writing everything in C++ removes the need to write and use wrapper code in managed C++. So I sat down and ported - or better - completely rewrote the editor from scratch. This is the result:

A simple 3D editor, with nearly the same functionality, once written in C# and once in C++

There are small differences between these two versions, for example some toolbar icons or menu entries are still missing, and the docking controls look a bit different due to the completely unrelated used docking frameworks, but everything works and is usable. It is quite interesting to compare the results of this work. For example, the common myth (which I believed too, until now) that you are developing applications faster with C# is now dead for me. You cannot compare the development time of these editors (about 32 hours for the C# version and about 5 for the C++ version) because a lot of user interface research went into the first one. But you can compare amount of code: The C#/windows.forms editor needs about 70 KB of code, while C++/wxWidgets only needs 36 KBytes. Thats quite a difference. And interestingly, the code does exactly the same on both sides, I'm using libraries for the same stuff in both versions.

And there is another interesting thing: The C++/wxWidgets version is way faster. The C++ application starts up instantly (C# version always needs some seconds), all views and trees update faster, moving of windows is faster (repainting 3D stuff) and I even have the subjective impression that clicking buttons is presenting results faster. So now, where is the advatage of C# again? I'm a C# fan, but now a bit disillusioned. But who knows, maybe C# just is a bit slower when it works with mixed mode assemblies.


hm, quite interesting
2006-05-01 22:48:00

C# is extremely wrist unfriendly, tons of casting and braces. Boo is far better, a wonderful CLR language.

I'm scared, just tell me this doesnt mean Irrlicht.net is going to fall further behind. Having the editor in C# gave me hope Irrlicht.NET would start staying more up to date.
2006-05-02 00:03:00


any chance you could post a tutorial on integrating wxWidgets and irrlicht? Like a hello world with a File...Exit Menu or something?
2006-05-02 00:22:00

Good move Niko. And nice to see less c#/.net and more portable code.
2006-05-02 02:24:00

Hmm... I hope this wouldn't lead to freezing Irrlicht.NET development. I agree with rektide that editor in C# gives us hope on faster irr.net improvement :p

And some words on C# speed and code size:
- are you using 2.0 framework? Generics and other improvements, as well as much better vs2005 ui really push up development :)
- C# is my main language and therefore i often see that code written by me in csharp is smaller and faster than cpp, when it should be slower :)
2006-05-02 02:31:00

man why does everybody hate on .NET? seriously its a great platform...
2006-05-02 04:21:00

Owww...I've heard of wxWidget before. But I've never tried it because it has a linux/unix tie for some reason in my mind. I have nothing against linux/unix. It just conjures up images of balding, morbidly obese old programmers who are both anal and emotionless. I don't want to associate myself with such images. :)

Then I read this blog post. Before you know it, I've downloaded and installed wxWidget on my 'puter. I've skimmed through the hello world tutorial and tried out the gui demo in the bin folder. It's not bad.

I've programmed gui apps on windows using visual c++ 6, MFC, VB, VB.NET, window forms with C#, WSH, and with pure win32 api(!).

Fantastic, niko! I love your blog posts!
2006-05-02 07:04:00

I don't think anyone here "hates" .NET (I know I don't). However, just because I do not hate something does not mean that it is perfect for all tasks.

.NET is basically Microsoft's Java (or more accurately - CLR is Microsoft's JVM). It has it's uses, but when it comes to speed, cross-platform compatibility, and memory consumption - it pales compared to C++. It is easier to debug than C++ due to the lack of "memory leaks" (as .NET is garbage collected), but memory consumption/turnover is still an issue for anything larger than a "test demo" (trust me, there are some .NET garbage collection issues that can really trash an application's performance!)

Personally, I prefer C++ and am kind of interested in seing Niko's wxWindows based "Irrlicht Editor". I have found wxWindows very easy to use and the idea of embedding Irrlicht within it makes me smile :)

Eternl Knight
2006-05-02 07:46:00

Yeah, and C++ is that wonderful god which can do everything and takes you to wonderland ... *looks-at-the-most-software-which-have-lots-of-security-leaks*
2006-05-02 08:01:00

Phu! Does this mean your .NET Wrapper development won't continue..? Okay, it does not affect our C#(!!) RPG Toolset Development as we use our own MixedMode Assembly for 'communication' with the Irrlicht Engine - but I think this is bad news for the .NET Irrlicht Community... - let's hope, that irrlicht# will make its way!

I can hardly understand your reasons for switching over to wxWidgets - particularly etcaptor is writing an Irrlicht Editor in C++ and the Irrlicht .NET Community needs more 'support' - so your .NET Editor would have been a valuable tool...

just my 2 cents!
Duncan Mac Leod
2006-05-02 16:11:00

.NET is pretty cool... but I have to favor the C++ version right now until .NET sees more improvement and more cross-platform distribution. I mean Niko can do it in C++ and wxWidgets and get it to how many platforms very stable and quickly... but .NET, not quite as much. Don't get me wrong, it's great and all, but I think for THIS particular application, c++ is the way to go.
2006-05-02 16:35:00

Dissapointed... I was hoping for some real progress on the .NET side, Irrlicht.NET is badly lagging behind C++ and the switch back to (unmanaged) C++ adds to the lag...

"because writing everything in (unmanaged) C++ removes the need to write and use wrapper code in managed C++. " ..please don't forget the wrapper is desperatly needed for everyone wanting to develop in Irrlicht.NET and many people have that need.
2006-05-03 03:56:00

I still don't get why people are so hooked on .NET, I've messed with it at work and I think it provides no enhancement to C++ at all.

Some big things I didn't like were the major differences between classes and structs in C#, as well as the inability to use multiple case statements in a switch for a single result.
2006-05-03 13:53:00

Well, the good news is, http://irrlichtsharp.sf.net is still going strong for people who need a .NET solution (that is, if Irrlicht.NET is discontinued)
2006-05-03 20:28:00

Ah, come on, no, Irrlicht.NEt won't suffer from this. :) BTW: looking for irrlichtsharp to make progress, would be interesting to compare both implementations. :)
2006-05-03 21:59:00

Whoa! Looks like alot of the .NET'ers have issues with C++. Nobody said C++ was the best langauge/library-set out there. Simply that we prefer it for the task of graphics engine development.

And for those criticising Niko for deciding how t best spend HIS freetime (i.e. complaining because he is using wxWindows rather than .NET) - remember that it is HIS right to determine what he does, not yours. It always annoys me when people complain about the direction of development they are not paying for.

Eternl Knight
2006-05-04 04:12:00

I completely agree with Eternl Knight.

Besides I hope Irrlicht development (in C++) won't lag, because of the development of .NET version...
2006-05-05 01:56:00

it seems like there is almost a linux-vs-windows style flamewar brewing between .NET and C++ users...
I suppose we all have our preference, but i think id have to be on the .NET side...
I like c++, but .NET is a lot easier to use/more programmer friendly.
2006-05-05 21:47:00

I remember that Borland made Kylix for linux based on their visual library, but they was stopped development and this software don't works with new kernels. Two years ago they made their C++BuilderX with wxWidgets RAD based preview. I was happy to compile Irrlicht with it. Despide cross compilers support, development of this product was stopped too. But this is a trace, that Borland likes wxWidgets ;-)
I suggest that Codeblocks team works on RAD system based on wxWidgets. So, every choice have own strong and weeks features.
But in both cases we can learn something in addition.
2006-05-06 07:48:00

Hi Niko,

this is good news, as i have fumbled around with wxWidgets myself. Did i miss something, or is IrrEdit not available (yet?). Would be cool to open it up for others to contribute to the development... I'd like to take a shoot at C++/wxWidget development, seems pretty straightforward.
Christophe Leske
2006-05-15 22:15:00

I am quite puzzled by the assumptions made by this "experiment".
To be exact: if the slowness and chubbyness of the implementation is caused exlusively by Windows.Forms?
I think this is the cause.

I am not pro-managed neither pro-native, but it's difficult to found valuable experiments of managed/native comparison.
I only found two applications: Jake 2 and Quake2.NET, both derived from Quake2, which showed that state-of-the-art programming in managed code lost about 15% compared to state-of-the-art native code (which, by the way, was C++ AND assembler).

I think it would be very interesting only the comparison of C# and C++ both using WxWidgets, and not C#/W.Forms and C++/WxWidgets.
2006-08-13 15:54:00

Add comment:

Posted by:

Enter the missing letter in: "Intern?tional"




Possible Codes

Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]