Archive for January, 2008

Highly customizable C++ template String class

Wednesday, January 30th, 2008

In my last contract, we used CEGUI for the User Interface. The String class provided and used by CEGUI uses an internal array as quick buffer for small strings, and reverts to the heap when the data doesn’t fit that quick buffer.
That approach increases performance if the quick buffer is big enough to hold most of your string operations.

However it lacks some features:

  • The quick buffer size is hard-coded in the class, instead of template-based.
  • When reverting to heap based, it doesn’t use any mechanisms to minimize allocations/ deallocations, like for example (Reference counting and Copy-On-Write)

Since I’m starting a new hobby project (my own small game engine), to test ideas and learn some new things, the first thing I’m coding is my own String class, which I’m also using as an exercise to test some more advanced templates stuff, instead of the classical “container of values of type T”.

So… about my String class.

Features:

  • Completely template based, using policies like described in the book Modern C++. This allows for a great deal of customization.
  • Using policies, it supports multiple types of string storage. Currently it support 2 storage types:
    • Heap based with reference counting and Copy-On-Write, to delay memory allocations/deallocations as much as possible.
    • Quick buffer based (like CEGUI), but with fallback to Heap based like described above when the data doesn’t fit the quick buffer. Also, the quick buffer size itself is a template parameter, so we set the size based on the use we have in mind.
  • We can mix strings declared with different policies (the ones provided), and internally it will still try to minimize memory allocations/deallocations, by using reference counting and Copy-On-Write when possible.
  • We can specify our own Allocator for heap based strings
  • Basic methods for manipulations. I need to implement a lot more.

Missing/Todo:

  • More methods for manipulations (make it more compatible with the std::string)
  • Unicode support. I’ve laid down the bases for that, but currently only works with char type

When coding it, I’ve used CppUnite2 for the tests. See this link for more information (Games from Within: CppUnitLite2 1.1).

I haven’t used this String class in a complex product yet, only in the tests during development, so I can’t talk about performance or bugs yet.

If you want to check it out, download it below:

NOTE: I’ve only tested it with Visual Studio 2005 (with sp1), so the provided project files are for that same compiler.

czString Download

Possible downtime of the site

Friday, January 25th, 2008

My Web Hosting provider is upgrading their servers sometime during the next days (between 25-28 January), so this website will probably be down for ~1hour… That is, if everything goes right.

If you’re one of the employers I had/will have interviews with, and you’re reading this, I really hope the site won’t offline for too long.

czPlayer 0.2.0 released

Monday, January 7th, 2008

I’ve been working hard on czPlayer, and here is the result. Version 0.2.0 released.
The API is mostly incompatible with the previous 0.1.1 version.
I’ve made a lot of changes to this version and added some new features, so I decided to jump the version number to 0.2.0.
All the internal refactoring I’ve made will hopefully allow me to add some new features I have in mind, like DSP effects (both internal and user provided) .
Needless to say, I’m not particularly confident about the stability of this version, with all the changes I’ve made. Some functions were not even tested yet. But like I said in earlier posts, there is always something to fix or improve, so I better release and work from there, than to keep fixing/improving stuff and never release.
I have so many crazy ideas for features! But most of them will not be implemented, because of the targeted platforms.
Codesize and performance have priority, not features… well… at least for czPlayer.
That leads me to another thing I’ve been thinking about…
Maybe I’ll eventually fork czPlayer into Mobile and Non-Mobile versions, so that I can go wild on all the things I want to implement. Hehe
Most of what I dislike in czPlayer (both internal, and in the external API), are a direct consequence of the compromises I had to make to support the targeted platforms, and have the same API for all of them.
Nuff said… You’ve got to ask yourself one question: “Do I feel lucky? Well, do you, punk ?

If so, go ahead, download the new version and give it a try:
Download lastest czPlayer demo.