13 December 2007

Not Invented Here Syndrome

This is something I definitely don't have. I'm a bit of a hoarder, a magpie maybe, collecting shiny things. When I encounter a seemingly useful piece of code on the Internet I would download it and dump it into my downloads directory. I've probably got gigabytes of the stuff.

I don't know what it is. I certainly feel that whatever I try to do someone must have at least tried it out before, so Google is my best friend in that respect.

You could say it is because C++ has so much not in the standard library that is available in frameworks like .NET and others. Maybe, but then that gives you choice and encourages you to think about the problem you are trying to solve and the best solution that you can come up with.

Fortunately loads of these tools and libraries are open-source so it is possible to help improve the baseline of thee libraries. Unfortunately you need to know where to look to find these as there is no central resource that can point you in the right direction to find the libraries that would be best for you. The closest I have found is the Free Game Development Libraries Page.

I think one of the skills I have picked up from being such a magpie is the ability to look at other people's code and to bend it to my own devices. Say for instance there is something useful, but not quite what I want on CodeProject, I'd refactor the code (way too much avoids encapsulation over there) and bring it in line with my own coding guidelines. I am then in a position to use and extend the code further.

Not Invented Here Syndrome I don't see as a good thing or at least a strict adherence to it is a weaknes. By reusing code you also have the possibility of giving something back as well to the potential "state of the art". Certainly not all code should be off-the-shelf and cookie cutter simplified implementations but it should provide the basis of what you are doing in order to avoid reinventing the wheel. I certainly see understanding someone else's code as an important skill in development.

STLPort Visual Studio 2005 Visualisers - autoexp.dat

Thanks to a comment on one of the posts about autoexp.dat and STLPort where I did a bit of a ham-fisted attempt at creating visualisers for STL containers in the Visual Studio 2005 debugger, I have been informed that there is a much better (and more comprehensive) version than my hack.

Now as part of the upcoming version 5.2 of STLPort there is a comprehensive and well written set of visualisers. This means debugging is now on parity with the in-built Microsoft containers. The version linked to in this post is for 5.2 but does work well with 5.1.

You can get the autoexp.dat edits here. It points to the Subversion repository head version. Since it will be part of the distribution it should be maintained and provides another excellent reason for using it (as well as the performance).

If anyone is using my hack then please use this version from the good people at STLPort - it is much better!

I suppose now it would be nice to have something similar for Boost...

07 December 2007

Multithreading - Make Me Parallel!

Sometimes even being multithreaded isn't even enough. Obviously running multiple processes simultaneously is great and all but it depends how heavyweight the processes are as you could be spending a lot of calculation time in a single process not giving much more than a responsive GUI during calculation (not making the most of the computing power). What you really want to do is divide those processes into their smallest components and parallelise those.

One of the tools freely available to C++ developers to accomplish these types of tasks is Threading Building Blocks which was open-sourced this year by Intel. In fact, I am pretty sure I mentioned this before, but I am nearly thirty so my brain ain't what it used to be. There are actually two parts to the library, a thread-safe set of allocators and the multithreading library including algorithms and thread-safe containers.

It is designed with the STL in mind (I suppose the developers would hope for an eventual inclusion into the standard library). It seems to be designed at a higher level semantically than a lot of other threading libraries and could help people to try it out much faster.

The most obvious place to try out some of the parallelisation is the "parallel_for" loop. It's interesting that speed optimisation can be tried out with a "grain size" as it is a trade off between the overhead of performing parallel operations and making use of the processor(s). It all works in a similar fashion to the normal STL algorithms and containers with some additional classes like "ranges" for the begin and end of your divided up operation. In fact it all seems so strangely easy to do, if you have to do calculations and construct new data, stick them in one of the thread-safe containers and you will be laughing. Admittedly if you do use "normal loops" in your code, you need to STL-ise them, but that is a fairly trivial operation to turn them into functors.

All in all though it looks quite good, and easy to use if you are parallelising simple loops. I am sure some programs will find substantial speed-ups and blow up a few CPUs with over-use from that. I could tell you a story that Intel tech support said we shouldn't run a Pentium III CPU at 100% use consistently back in the day...

03 December 2007

Cool Use For Virtualisation

Virtualisation is obviously the hot computing technology of the moment. We make good use of virtualisation where I work in order to really get around weird Windows limitations where it seems dislike multithreading.

The good thing now is VMWare Workstation is free so you can use images anywhere.

What impressed me though is that as part of the pursuit of X-Box Media Centre for Linux they have the entire development environment available as a VMWare image. That makes life so much easier for developers! It means you don't have to fiddle with your settings and deal with other potential conflicts.

It is just a great way to use the technology and lower the barriers for development and guarantee a consistent development environment. Obviously it is not the official way to do it but the fact it exists is pretty darn good.