Object Pool Management

I'm always looking for performances (too much I guess) and everybody knows that a malloc/free is expensive. That's why I was using a Object (can be Unit, Towers, Ammos....) array as a fixed memory and a vector of Object pointer as a list pointing to some of the array objects. The only problem was about the constructor. I didn't find a way to call it without "new"

That's why I took a look at the boost library. In the first hand, they have a constructor template to call the constructor. This is the first cool thing! The other one is the object_pool (from the boost::pool) which does exactly what I was doing before (Except it uses the constructor). There is no big improvement in the game but it is now a bit more clean.

For the fun I tried to fill the map with towers. It was the Debug mode (even worth, I was debugging it), and my cpu was in low mode (in FullScreen). It's still running at 60fps all the time (don't look at the screen fps, the screen print really slows down the fps during the screen shot). I'm happy for that.

During those days I've read a lot about metaprogramming, which is really interesting. Specially because it can be done in C++ directly in the code with the boost::mpl library.

The game makes me learn some cool new features of the next C++ (and also the current TR1 and...)
I really advice any new programmer to read tutorials about boost to start a new project.

Multiplayer : lot of towers

Comments

You should always benchmark

You should always benchmark before and after the optimization because a lot of time you think you optimize your code but it is very often worse xD. Also, NEVER test the performance in debug mode because in optimization enabled it happens very often that a code that is slower than another in debug can be 10 time faster with the optimization enabled...

Tanek

Better than a benchmark

You are right, it is good to perform some test and benchmark after any optimization. I have a benchmark map to do that but it is not enough for me. I use a profiler to analyze the optimization. It gives more informations, and allows you to see if your optimizations are doing what you expected. You can also find if the optimization has an impact on another part of the game. The MVC system (Model,View,Controller) allows me to run each component separately if needed. Like this I can benchmark only the model (which will be the server) or only the graphic engine.

Another work I do before implementing a optimization like this in the game is to write a program dedicated to this optimization and to compare all the possible solutions (I got some surprises sometimes). Even if those programs are not 100% accurate, it is a good thing to start with.