• entries
    383
  • comments
    1075
  • views
    352269

C++ for C programmers

Sign in to follow this  
Trapper Zoid

56 views

I've come to the realisation that I'm not a C++ programmer; I'm just a C programmer in disguise.

In my understanding of the signal slot code I'm using I searched up a few tutorials on more advanced template use and stumbled across the C++ FAQ Lite, a wonderfully informative series of tips on proper C++ usage. After reading through a few of these I realised that I've been coding things the wrong way for ages. I've been using a C based approach for most of the things I do, only slowly incorporating a C++ like shell around the outside. I haven't yet learnt how to properly think like a C++ programmer when approaching problems; I'm still stuck in C like programming paradigms.

While I'm getting a bit annoyed at my slow progress on my Diagonal library, I'm thinking it'll be worth taking my time if I use this to become a better C++ coder, rather than slip back into what I guess is the "C with Classes" approach I've been using for the last few years.


As for the signal system, I've performed another test comparing the sigslot library to the event passing system I coded up myself for use in my old collection of game code. My event system is a bit clunky: it's based on the SDL event system, it uses a singleton event manager for all events, is based on a virtual event handler function classes access via inheritance, and takes a pre-defined data structure as its input. But I wanted to see how the sigslot library compares against it for performance.

The result was that sigslot is about twice as fast as my event system for sending signals, however my event system was about twice as fast at intialistion and shutdown. Since initialisation and shutdown takes an order of magnitude more time than sending a signal this suggests that the sigslot system is more efficient in cases where many signals are being sent to each slot, whereas for only a few signals something simpler may be more efficient.

I've dug into the sigslot code some more to get a better understanding of how it works and how I can extend it to have the functionality I need. After drinking too much coffee the code started to make sense to me and I can see the gist of how the thing works. My main concern for performace's sake is that the system has to allocate a new chunk of memory every time a new signal slot connection is made; not just in the list of allocated slots that is called to send the signals on, but also within the slot itself so that when it is destroyed it can deallocate itself from any signals it has connected to. I'm always a bit wary of allocating memory myself in my programs; if you're not careful they can end up a performance bottleneck and there's always the danger of memory leaks. After getting used to the STL containers I now very rarely have to use "new" and "delete" in my code. However I'm probably just overinflating the problem here, and I'm sure it'll be fine for the initial version at least.


Finally I'm a bit annoyed at my inability to finish my first proper piece of BlockyMan music that I've been working on for the last month or so. The tune is fine, but I keep screwing up the backing. I think I might just be trying too hard to do something fancy and something simpler would work a lot better.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now