The current shared pointer implementation Ogre uses, on threaded builds, ends up consuming a whopping 5*sizeof(void*) bytes of memory; the resulting effective structure looks something like
Creating a new shared pointer object therefore requires two additional allocations (one for the reference count, one for the mutex).
Additionally, modifications to a shared pointer require a mutex, even though nigh every CPU Ogre supports can handle atomic increments and decrements.
Finally, a convoluted system of subclasses is used to provide free casting between Resource subclasses, at the expense of type safety.
Ogre's shared pointers are both huge and slow. The interface SharedPtr/std::shared_ptr provides can be implemented efficiently using only two pointers plus one additional allocation per pointee.
Lets fix this:
The first change this patch makes is to isolate the per-object information (the reference count, deletion method, and if necessary mutex) into a single instance of new struct SharedPtrInfo
The second change is to add starticCast/dynamicCast member methods to SharedPtr, to provide cast capability equal to that provided by the standard static_cast/dynamic_cast
This change has then been retrofitted throughout the codebase.
This does make some uses of the resource manager APIs more complex; but with the changes I'm making for GSOC this will be a non-issue anyhow.
These changes bring the smart pointer implementation in Ogre up to the standard found elsewhere