Index: /code/branches/consolecommands3/src/libraries/util/CMakeLists.txt
===================================================================
--- /code/branches/consolecommands3/src/libraries/util/CMakeLists.txt	(revision 7263)
+++ /code/branches/consolecommands3/src/libraries/util/CMakeLists.txt	(revision 7264)
@@ -32,6 +32,8 @@
   OutputHandler.cc
   ScopedSingletonManager.cc
+  SharedPtr.cc
   SignalHandler.cc
   Sleep.cc
+  SmallObjectAllocator.cc
   SubString.cc
 COMPILATION_END
Index: /code/branches/consolecommands3/src/libraries/util/SharedPtr.cc
===================================================================
--- /code/branches/consolecommands3/src/libraries/util/SharedPtr.cc	(revision 7264)
+++ /code/branches/consolecommands3/src/libraries/util/SharedPtr.cc	(revision 7264)
@@ -0,0 +1,38 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "SharedPtr.h"
+
+namespace orxonox
+{
+    SmallObjectAllocator& createSharedCounterPool()
+    {
+        static SmallObjectAllocator instance(sizeof(SharedCounterImpl<void>));
+        return instance;
+    }
+}
Index: /code/branches/consolecommands3/src/libraries/util/SharedPtr.h
===================================================================
--- /code/branches/consolecommands3/src/libraries/util/SharedPtr.h	(revision 7263)
+++ /code/branches/consolecommands3/src/libraries/util/SharedPtr.h	(revision 7264)
@@ -31,20 +31,26 @@
 
 #include "UtilPrereqs.h"
+
 #include <algorithm>
 #include <cassert>
 
+#include "SmallObjectAllocator.h"
+
 namespace orxonox
 {
-    class SharedPtrDestroyer
+    class SharedCounter
     {
         public:
+            SharedCounter() : count_(1) {}
             virtual void destroy() = 0;
+
+            int count_;
     };
 
     template <class T>
-    class SharedPtrDestroyerImpl : public SharedPtrDestroyer
+    class SharedCounterImpl : public SharedCounter
     {
         public:
-            SharedPtrDestroyerImpl(T* pointer) : pointer_(pointer) {}
+            SharedCounterImpl(T* pointer) : pointer_(pointer) {}
 
             void destroy()
@@ -57,4 +63,12 @@
     };
 
+    _UtilExport SmallObjectAllocator& createSharedCounterPool();
+
+    FORCEINLINE SmallObjectAllocator& getSharedCounterPool()
+    {
+        static SmallObjectAllocator& instance = createSharedCounterPool();
+        return instance;
+    }
+
     template <class T>
     class SharedPtr
@@ -64,28 +78,28 @@
 
         public:
-            inline SharedPtr() : pointer_(0), counter_(0), destroyer_(0)
+            inline SharedPtr() : pointer_(0), counter_(0)
             {
             }
 
-            inline SharedPtr(T* pointer) : pointer_(pointer), counter_(0), destroyer_(0)
+            inline SharedPtr(T* pointer) : pointer_(pointer), counter_(0)
             {
                 if (this->pointer_)
                 {
-                    this->counter_ = new int(1);
-                    this->destroyer_ = new SharedPtrDestroyerImpl<T>(this->pointer_);
+                    void* chunk = getSharedCounterPool().alloc();
+                    this->counter_ = new (chunk) SharedCounterImpl<T>(this->pointer_);
                 }
             }
 
-            inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_), counter_(other.counter_), destroyer_(other.destroyer_)
+            inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_), counter_(other.counter_)
             {
                 if (this->pointer_)
-                    ++(*this->counter_);
+                    ++this->counter_->count_;
             }
 
             template <class O>
-            inline SharedPtr(const SharedPtr<O>& other) : pointer_(other.pointer_), counter_(other.counter_), destroyer_(other.destroyer_)
+            inline SharedPtr(const SharedPtr<O>& other) : pointer_(other.pointer_), counter_(other.counter_)
             {
                 if (this->pointer_)
-                    ++(*this->counter_);
+                    ++this->counter_->count_;
             }
 
@@ -94,11 +108,10 @@
                 if (this->pointer_)
                 {
-                    --(*this->counter_);
+                    --this->counter_->count_;
 
-                    if (*this->counter_ == 0)
+                    if (this->counter_->count_ == 0)
                     {
-                        this->destroyer_->destroy();
-                        delete this->destroyer_;
-                        delete this->counter_;
+                        this->counter_->destroy();
+                        getSharedCounterPool().free(this->counter_);
                     }
                 }
@@ -122,5 +135,5 @@
             {
                 O* temp = static_cast<O*>(this->pointer_); // temp value for prettier compiler error in case of an invalid static_cast
-                return SharedPtr<O>(temp, this->counter_, this->destroyer_);
+                return SharedPtr<O>(temp, this->counter_);
             }
 
@@ -151,17 +164,15 @@
                 std::swap(this->pointer_, other.pointer_);
                 std::swap(this->counter_, other.counter_);
-                std::swap(this->destroyer_, other.destroyer_);
             }
 
         private:
-            inline SharedPtr(T* pointer, int* counter, SharedPtrDestroyer* destroyer) : pointer_(pointer), counter_(counter), destroyer_(destroyer)
+            inline SharedPtr(T* pointer, SharedCounter* counter) : pointer_(pointer), counter_(counter)
             {
                 if (this->pointer_)
-                    ++(*this->counter_);
+                    ++this->counter_->count_;
             }
 
             T* pointer_;
-            int* counter_;
-            SharedPtrDestroyer* destroyer_;
+            SharedCounter* counter_;
     };
 
Index: /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.cc
===================================================================
--- /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.cc	(revision 7264)
+++ /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.cc	(revision 7264)
@@ -0,0 +1,87 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "SmallObjectAllocator.h"
+
+namespace orxonox
+{
+    SmallObjectAllocator::SmallObjectAllocator(size_t objectSize, size_t numObjects)
+    {
+        this->objectSize_ = std::max(objectSize, sizeof(Chunk));
+        this->numObjects_ = numObjects;
+        this->first_ = 0;
+    }
+
+    SmallObjectAllocator::~SmallObjectAllocator()
+    {
+        for (std::vector<char*>::iterator it = this->blocks_.begin(); it != this->blocks_.end(); ++it)
+            delete[] *it;
+    }
+
+    /* static */ void SmallObjectAllocator::setNext(void* chunk, void* next)
+    {
+        static_cast<Chunk*>(chunk)->next_ = static_cast<Chunk*>(next);
+    }
+
+    /* static */ void* SmallObjectAllocator::getNext(void* chunk)
+    {
+        return static_cast<Chunk*>(chunk)->next_;
+    }
+
+    void* SmallObjectAllocator::alloc()
+    {
+        void* chunk = this->first_;
+
+        if (chunk)
+        {
+            this->first_ = getNext(chunk);
+        }
+        else
+        {
+            char* block = new char[this->objectSize_ * this->numObjects_];
+            this->blocks_.push_back(block);
+
+            for (size_t i = 1; i < this->numObjects_ - 1; ++i)
+                setNext(block + i * this->objectSize_, block + (i + 1) * this->objectSize_);
+
+            setNext(block + (this->numObjects_ - 1) * this->objectSize_, 0);
+
+            this->first_ = block + this->objectSize_;
+
+            chunk = block;
+        }
+
+        return chunk;
+    }
+
+    void SmallObjectAllocator::free(void* chunk)
+    {
+        setNext(chunk, this->first_);
+        this->first_ = chunk;
+    }
+}
Index: /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.h
===================================================================
--- /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.h	(revision 7264)
+++ /code/branches/consolecommands3/src/libraries/util/SmallObjectAllocator.h	(revision 7264)
@@ -0,0 +1,63 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _SmallObjectAllocator_H__
+#define _SmallObjectAllocator_H__
+
+#include "UtilPrereqs.h"
+#include <vector>
+
+namespace orxonox
+{
+    class _UtilExport SmallObjectAllocator
+    {
+        struct Chunk
+        {
+            Chunk* next_;
+        };
+
+        public:
+            SmallObjectAllocator(size_t objectSize, size_t numObjects = 64);
+            ~SmallObjectAllocator();
+
+            void* alloc();
+            void free(void* chunk);
+
+        private:
+            static void setNext(void* chunk, void* next);
+            static void* getNext(void* chunk);
+
+            void* first_;
+            size_t objectSize_;
+            size_t numObjects_;
+
+            std::vector<char*> blocks_;
+    };
+}
+
+#endif /* _SmallObjectAllocator_H__ */
