瀏覽代碼

Added custom allocator for most STL containers

Marko Pintera 12 年之前
父節點
當前提交
f215bc5700

+ 2 - 2
BansheeEngine/Include/BsSceneManager.h

@@ -14,12 +14,12 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Returns all cameras in the scene.
 		 * @brief	Returns all cameras in the scene.
 		 */
 		 */
-		virtual const std::vector<HCamera>& getAllCameras() const = 0;
+		virtual const CM::vector<HCamera>::type& getAllCameras() const = 0;
 
 
 		/**
 		/**
 		 * @brief	Returns all renderables visible to the specified camera.
 		 * @brief	Returns all renderables visible to the specified camera.
 		 */
 		 */
-		virtual std::vector<HRenderable> getVisibleRenderables(const HCamera& camera) const = 0;
+		virtual CM::vector<HRenderable>::type getVisibleRenderables(const HCamera& camera) const = 0;
 	};
 	};
 
 
 	BS_EXPORT SceneManager& gSceneManager();
 	BS_EXPORT SceneManager& gSceneManager();

+ 3 - 3
BansheeOctreeSM/Include/BsOctreeSceneManager.h

@@ -11,13 +11,13 @@ namespace BansheeEngine
 		OctreeSceneManager() {}
 		OctreeSceneManager() {}
 		~OctreeSceneManager() {}
 		~OctreeSceneManager() {}
 
 
-		const std::vector<HCamera>& getAllCameras() const { return mCachedCameras; }
+		const CM::vector<HCamera>::type& getAllCameras() const { return mCachedCameras; }
 
 
-		std::vector<HRenderable> getVisibleRenderables(const HCamera& camera) const;
+		CM::vector<HRenderable>::type getVisibleRenderables(const HCamera& camera) const;
 	private:
 	private:
 		void notifyComponentAdded(const CM::HComponent& component);
 		void notifyComponentAdded(const CM::HComponent& component);
 		void notifyComponentRemoved(const CM::HComponent& component);
 		void notifyComponentRemoved(const CM::HComponent& component);
 
 
-		std::vector<HCamera> mCachedCameras;
+		CM::vector<HCamera>::type mCachedCameras;
 	};
 	};
 }
 }

+ 1 - 1
BansheeOctreeSM/Source/BsOctreeSceneManager.cpp

@@ -9,7 +9,7 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	std::vector<HRenderable> OctreeSceneManager::getVisibleRenderables(const HCamera& camera) const
+	vector<HRenderable>::type OctreeSceneManager::getVisibleRenderables(const HCamera& camera) const
 	{
 	{
 		// TODO - Cull invisible objects
 		// TODO - Cull invisible objects
 
 

+ 4 - 4
CamelotCore/Include/CmFontDesc.h

@@ -96,7 +96,7 @@ namespace CamelotFramework
 				+ sizeof(data.yOffset)
 				+ sizeof(data.yOffset)
 				+ sizeof(data.xAdvance)
 				+ sizeof(data.xAdvance)
 				+ sizeof(data.yAdvance)
 				+ sizeof(data.yAdvance)
-				+ RTTIPlainType<std::vector<KerningPair>>::getDynamicSize(data.kerningPairs);
+				+ RTTIPlainType<vector<KerningPair>::type>::getDynamicSize(data.kerningPairs);
 
 
 			dataSize += sizeof(UINT32);
 			dataSize += sizeof(UINT32);
 
 
@@ -116,7 +116,7 @@ namespace CamelotFramework
 			memcpy(memory, &size, sizeof(UINT32));
 			memcpy(memory, &size, sizeof(UINT32));
 			memory += sizeof(UINT32);
 			memory += sizeof(UINT32);
 			
 			
-			RTTIPlainType<std::map<UINT32, CHAR_DESC>>::toMemory(data.characters, memory);
+			RTTIPlainType<map<UINT32, CHAR_DESC>::type>::toMemory(data.characters, memory);
 			rttiWriteElem(data.baselineOffset, memory);
 			rttiWriteElem(data.baselineOffset, memory);
 			rttiWriteElem(data.lineHeight, memory);
 			rttiWriteElem(data.lineHeight, memory);
 			rttiWriteElem(data.missingGlyph, memory);
 			rttiWriteElem(data.missingGlyph, memory);
@@ -129,7 +129,7 @@ namespace CamelotFramework
 			memcpy(&size, memory, sizeof(UINT32)); 
 			memcpy(&size, memory, sizeof(UINT32)); 
 			memory += sizeof(UINT32);
 			memory += sizeof(UINT32);
 
 
-			RTTIPlainType<std::map<UINT32, CHAR_DESC>>::fromMemory(data.characters, memory);
+			RTTIPlainType<map<UINT32, CHAR_DESC>::type>::fromMemory(data.characters, memory);
 			rttiReadElem(data.baselineOffset, memory);
 			rttiReadElem(data.baselineOffset, memory);
 			rttiReadElem(data.lineHeight, memory);
 			rttiReadElem(data.lineHeight, memory);
 			rttiReadElem(data.missingGlyph, memory);
 			rttiReadElem(data.missingGlyph, memory);
@@ -141,7 +141,7 @@ namespace CamelotFramework
 		static UINT32 getDynamicSize(const FONT_DESC& data)	
 		static UINT32 getDynamicSize(const FONT_DESC& data)	
 		{ 
 		{ 
 			UINT64 dataSize = sizeof(UINT32);
 			UINT64 dataSize = sizeof(UINT32);
-			dataSize += RTTIPlainType<std::map<UINT32, CHAR_DESC>>::getDynamicSize(data.characters);
+			dataSize += RTTIPlainType<map<UINT32, CHAR_DESC>::type>::getDynamicSize(data.characters);
 			dataSize += rttiGetElemSize(data.baselineOffset);
 			dataSize += rttiGetElemSize(data.baselineOffset);
 			dataSize += rttiGetElemSize(data.lineHeight);
 			dataSize += rttiGetElemSize(data.lineHeight);
 			dataSize += rttiGetElemSize(data.missingGlyph);
 			dataSize += rttiGetElemSize(data.missingGlyph);

+ 1 - 1
CamelotCore/Include/CmRenderSystemCapabilities.h

@@ -198,7 +198,7 @@ namespace CamelotFramework
 
 
 		void fromString(const String& versionString)
 		void fromString(const String& versionString)
 		{
 		{
-			std::vector<CamelotFramework::String> tokens = StringUtil::split(versionString, ".");
+			vector<CamelotFramework::String>::type tokens = StringUtil::split(versionString, ".");
 			if(!tokens.empty())
 			if(!tokens.empty())
 			{
 			{
 				major = parseInt(tokens[0]);
 				major = parseInt(tokens[0]);

+ 2 - 1
CamelotCore/Include/CmTextureRTTI.h

@@ -7,6 +7,7 @@
 #include "CmMath.h"
 #include "CmMath.h"
 #include "CmApplication.h"
 #include "CmApplication.h"
 #include "CmDeferredRenderContext.h"
 #include "CmDeferredRenderContext.h"
+#include <boost/preprocessor/comma.hpp>
 
 
 // DEBUG ONLY
 // DEBUG ONLY
 #include "CmTextureManager.h"
 #include "CmTextureManager.h"
@@ -118,7 +119,7 @@ namespace CamelotFramework
 
 
 			gMainSyncedRC().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 			gMainSyncedRC().submitToGpu(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
 
 
-			CM_DELETE(pixelData, vector<PixelDataPtr>, PoolAlloc);
+			CM_DELETE(pixelData, vector<PixelDataPtr BOOST_PP_COMMA() StdGenAlloc<PixelDataPtr>>, PoolAlloc);
 			texture->mRTTIData = nullptr;	
 			texture->mRTTIData = nullptr;	
 		}
 		}
 
 

+ 4 - 2
CamelotD3D11RenderSystem/Source/CmD3D11InputLayoutManager.cpp

@@ -7,6 +7,8 @@
 #include "CmDebug.h"
 #include "CmDebug.h"
 #include "CmUtil.h"
 #include "CmUtil.h"
 
 
+#include "boost/preprocessor/comma.hpp"
+
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
 	size_t D3D11InputLayoutManager::HashFunc::operator()
 	size_t D3D11InputLayoutManager::HashFunc::operator()
@@ -55,7 +57,7 @@ namespace CamelotFramework
 		{
 		{
 			auto firstElem = mInputLayoutMap.begin();
 			auto firstElem = mInputLayoutMap.begin();
 
 
-			CM_DELETE(firstElem->first.bufferDeclElements, list<VertexElement>, PoolAlloc);
+			CM_DELETE(firstElem->first.bufferDeclElements, list<VertexElement BOOST_PP_COMMA() StdGenAlloc<VertexElement>>, PoolAlloc);
 			SAFE_RELEASE(firstElem->second->inputLayout);
 			SAFE_RELEASE(firstElem->second->inputLayout);
 			CM_DELETE(firstElem->second, InputLayoutEntry, PoolAlloc);
 			CM_DELETE(firstElem->second, InputLayoutEntry, PoolAlloc);
 
 
@@ -166,7 +168,7 @@ namespace CamelotFramework
 		{
 		{
 			auto inputLayoutIter = mInputLayoutMap.find(iter->second);
 			auto inputLayoutIter = mInputLayoutMap.find(iter->second);
 
 
-			CM_DELETE(inputLayoutIter->first.bufferDeclElements, list<VertexElement>, PoolAlloc);
+			CM_DELETE(inputLayoutIter->first.bufferDeclElements, list<VertexElement BOOST_PP_COMMA() StdGenAlloc<VertexElement>>, PoolAlloc);
 			SAFE_RELEASE(inputLayoutIter->second->inputLayout);
 			SAFE_RELEASE(inputLayoutIter->second->inputLayout);
 			CM_DELETE(inputLayoutIter->second, InputLayoutEntry, PoolAlloc);
 			CM_DELETE(inputLayoutIter->second, InputLayoutEntry, PoolAlloc);
 
 

+ 1 - 1
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -155,7 +155,7 @@ namespace CamelotFramework
 
 
 		checkForErrors();
 		checkForErrors();
 
 
-		std::vector<CamelotFramework::String> tokens = StringUtil::split(mGLSupport->getGLVersion(), ".");
+		vector<CamelotFramework::String>::type tokens = StringUtil::split(mGLSupport->getGLVersion(), ".");
 
 
 		if (!tokens.empty())
 		if (!tokens.empty())
 		{
 		{

+ 101 - 0
CamelotUtility/Include/CmMemoryAllocator.h

@@ -1,5 +1,8 @@
 #pragma once
 #pragma once
 
 
+#undef min
+#undef max
+
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
 	/**
 	/**
@@ -110,4 +113,102 @@ namespace CamelotFramework
 #define CM_DELETE_BYTES(ptr, category) CamelotFramework::MemoryAllocator<category>::free(ptr)
 #define CM_DELETE_BYTES(ptr, category) CamelotFramework::MemoryAllocator<category>::free(ptr)
 #define CM_DELETE_ARRAY(ptr, T, count, category) CamelotFramework::__cm_destruct_array<T, category>(ptr, count)
 #define CM_DELETE_ARRAY(ptr, T, count, category) CamelotFramework::__cm_destruct_array<T, category>(ptr, count)
 
 
+namespace CamelotFramework
+{
+	// Allocators we can use in the standard library
+	
+	template <class T>
+	class StdGenAlloc 
+	{
+		public:
+		// type definitions
+		typedef T        value_type;
+		typedef T*       pointer;
+		typedef const T* const_pointer;
+		typedef T&       reference;
+		typedef const T& const_reference;
+		typedef std::size_t    size_type;
+		typedef std::ptrdiff_t difference_type;
+
+		// rebind allocator to type U
+		template <class U>
+		struct rebind 
+		{
+			typedef StdGenAlloc<U> other;
+		};
+
+		// return address of values
+		pointer address (reference value) const 
+		{
+			return &value;
+		}
+		const_pointer address (const_reference value) const 
+		{
+			return &value;
+		}
+
+		/* constructors and destructor
+		* - nothing to do because the allocator has no state
+		*/
+		StdGenAlloc() throw() 
+		{ }
+
+		StdGenAlloc(const StdGenAlloc&) throw() 
+		{ }
+
+		template <class U>
+		StdGenAlloc (const StdGenAlloc<U>&) throw() 
+		{ }
+
+		~StdGenAlloc() throw() 
+		{ }
+
+		// return maximum number of elements that can be allocated
+		size_type max_size () const throw() 
+		{
+			return std::numeric_limits<std::size_t>::max() / sizeof(T);
+		}
+
+		// allocate but don't initialize num elements of type T
+		pointer allocate (size_type num, const void* = 0) 
+		{
+			pointer ret = (pointer)(CM_NEW_BYTES((UINT32)num*sizeof(T), GenAlloc));
+			return ret;
+		}
+
+		// initialize elements of allocated storage p with value value
+		void construct (pointer p, const T& value) 
+		{
+			// initialize memory with placement new
+			new((void*)p)T(value);
+		}
+
+		// destroy elements of initialized storage p
+		void destroy (pointer p) 
+		{
+			// destroy objects by calling their destructor
+			p->~T();
+		}
+
+		// deallocate storage p of deleted elements
+		void deallocate (pointer p, size_type num) 
+		{
+			// print message and deallocate memory with global delete
+			CM_DELETE_BYTES((void*)p, GenAlloc);
+		}
+	};
+
+   // return that all specializations of this allocator are interchangeable
+   template <class T1, class T2>
+   bool operator== (const StdGenAlloc<T1>&,
+                    const StdGenAlloc<T2>&) throw() {
+       return true;
+   }
+   template <class T1, class T2>
+   bool operator!= (const StdGenAlloc<T1>&,
+                    const StdGenAlloc<T2>&) throw() {
+       return false;
+   }
+}
+
 #include "CmMemStack.h"
 #include "CmMemStack.h"

+ 8 - 8
CamelotUtility/Include/CmRTTIPrerequisites.h

@@ -89,11 +89,11 @@ namespace CamelotFramework
 	}; 
 	}; 
 
 
 	// RTTI types for some standard classes
 	// RTTI types for some standard classes
-	template<class T> struct RTTIPlainType<std::vector<T>>
+	template<class T> struct RTTIPlainType<std::vector<T, StdGenAlloc<T>>>
 	{	
 	{	
 		enum { id = TID_STDVECTOR }; enum { hasDynamicSize = 1 };
 		enum { id = TID_STDVECTOR }; enum { hasDynamicSize = 1 };
 
 
-		static void toMemory(const std::vector<T>& data, char* memory)
+		static void toMemory(const std::vector<T, StdGenAlloc<T>>& data, char* memory)
 		{ 
 		{ 
 			UINT32 size = (UINT32)data.size();
 			UINT32 size = (UINT32)data.size();
 
 
@@ -109,7 +109,7 @@ namespace CamelotFramework
 			}
 			}
 		}
 		}
 
 
-		static UINT32 fromMemory(std::vector<T>& data, char* memory)
+		static UINT32 fromMemory(std::vector<T, StdGenAlloc<T>>& data, char* memory)
 		{ 
 		{ 
 			UINT32 size;
 			UINT32 size;
 			memcpy(&size, memory, sizeof(UINT32)); 
 			memcpy(&size, memory, sizeof(UINT32)); 
@@ -127,7 +127,7 @@ namespace CamelotFramework
 			return size;
 			return size;
 		}
 		}
 
 
-		static UINT32 getDynamicSize(const std::vector<T>& data)	
+		static UINT32 getDynamicSize(const std::vector<T, StdGenAlloc<T>>& data)	
 		{ 
 		{ 
 			UINT64 dataSize = sizeof(UINT32);
 			UINT64 dataSize = sizeof(UINT32);
 
 
@@ -140,11 +140,11 @@ namespace CamelotFramework
 		}	
 		}	
 	}; 
 	}; 
 
 
-	template<class Key, class Value> struct RTTIPlainType<std::map<Key, Value>>
+	template<class Key, class Value> struct RTTIPlainType<std::map<Key, Value, std::less<Key>, StdGenAlloc<std::pair<const Key, Value>>>>
 	{	
 	{	
 		enum { id = TID_STDMAP }; enum { hasDynamicSize = 1 };
 		enum { id = TID_STDMAP }; enum { hasDynamicSize = 1 };
 
 
-		static void toMemory(const std::map<Key, Value>& data, char* memory)
+		static void toMemory(const std::map<Key, Value, std::less<Key>, StdGenAlloc<std::pair<const Key, Value>>>& data, char* memory)
 		{ 
 		{ 
 			UINT32 size = (UINT32)data.size();
 			UINT32 size = (UINT32)data.size();
 
 
@@ -165,7 +165,7 @@ namespace CamelotFramework
 			}
 			}
 		}
 		}
 
 
-		static UINT32 fromMemory(std::map<Key, Value>& data, char* memory)
+		static UINT32 fromMemory(std::map<Key, Value, std::less<Key>, StdGenAlloc<std::pair<const Key, Value>>>& data, char* memory)
 		{ 
 		{ 
 			UINT32 size;
 			UINT32 size;
 			memcpy(&size, memory, sizeof(UINT32)); 
 			memcpy(&size, memory, sizeof(UINT32)); 
@@ -187,7 +187,7 @@ namespace CamelotFramework
 			return size;
 			return size;
 		}
 		}
 
 
-		static UINT32 getDynamicSize(const std::map<Key, Value>& data)	
+		static UINT32 getDynamicSize(const std::map<Key, Value, std::less<Key>, StdGenAlloc<std::pair<const Key, Value>>>& data)	
 		{ 
 		{ 
 			UINT64 dataSize = sizeof(UINT32);
 			UINT64 dataSize = sizeof(UINT32);
 
 

+ 20 - 20
CamelotUtility/Include/CmStdHeaders.h

@@ -146,64 +146,64 @@ namespace CamelotFramework
 #endif
 #endif
 
 
 	// Standard containers, for easier access in my own namespace
 	// Standard containers, for easier access in my own namespace
-	template <typename T, typename A = char > 
+	template <typename T, typename A = StdGenAlloc<T>> 
 	struct deque 
 	struct deque 
 	{ 
 	{ 
-		typedef typename std::deque<T> type;    
+		typedef typename std::deque<T, A> type;    
 	}; 
 	}; 
 
 
-	template <typename T, typename A = char > 
+	template <typename T, typename A = StdGenAlloc<T>> 
 	struct vector 
 	struct vector 
 	{ 
 	{ 
-		typedef typename std::vector<T> type;    
+		typedef typename std::vector<T, A> type;    
 	}; 
 	}; 
 
 
-	template <typename T, typename A = char > 
+	template <typename T, typename A = StdGenAlloc<T>> 
 	struct list 
 	struct list 
 	{ 
 	{ 
-		typedef typename std::list<T> type;    
+		typedef typename std::list<T, A> type;    
 	}; 
 	}; 
 
 
-	template <typename T, typename A = char > 
+	template <typename T, typename A = StdGenAlloc<T>> 
 	struct stack 
 	struct stack 
 	{ 
 	{ 
-		typedef typename std::stack<T> type;    
+		typedef typename std::stack<T, std::deque<T, A>> type;    
 	}; 
 	}; 
 
 
-	template <typename T, typename P = std::less<T>, typename A = char > 
+	template <typename T, typename P = std::less<T>, typename A = StdGenAlloc<T>> 
 	struct set 
 	struct set 
 	{ 
 	{ 
-		typedef typename std::set<T, P> type;    
+		typedef typename std::set<T, P, A> type;    
 	}; 
 	}; 
 
 
-	template <typename K, typename V, typename P = std::less<K>, typename A = char > 
+	template <typename K, typename V, typename P = std::less<K>, typename A = StdGenAlloc<std::pair<const K, V>>> 
 	struct map 
 	struct map 
 	{ 
 	{ 
-		typedef typename std::map<K, V, P> type; 
+		typedef typename std::map<K, V, P, A> type; 
 	}; 
 	}; 
 
 
-	template <typename K, typename V, typename P = std::less<K>, typename A = char > 
+	template <typename K, typename V, typename P = std::less<K>, typename A = StdGenAlloc<std::pair<const K, V>>> 
 	struct multimap 
 	struct multimap 
 	{ 
 	{ 
-		typedef typename std::multimap<K, V, P> type; 
+		typedef typename std::multimap<K, V, P, A> type; 
 	}; 
 	}; 
 
 
-	template <typename T, typename A = char, typename B = char, typename C = char> 
+	template <typename T, typename H = std::hash<T>, typename C = std::equal_to<T>, typename A = StdGenAlloc<T>> 
 	struct unordered_set 
 	struct unordered_set 
 	{ 
 	{ 
-		typedef typename std::unordered_set<T> type;    
+		typedef typename std::unordered_set<T, H, C, A> type;    
 	}; 
 	}; 
 
 
-	template <typename K, typename V, typename A = char, typename B = char, typename C = char> 
+	template <typename K, typename V, typename H = std::hash<K>, typename C = std::equal_to<K>, typename A = StdGenAlloc<std::pair<const K, V>>> 
 	struct unordered_map 
 	struct unordered_map 
 	{ 
 	{ 
-		typedef typename std::unordered_map<K, V> type; 
+		typedef typename std::unordered_map<K, V, H, C, A> type; 
 	}; 
 	}; 
 
 
-	template <typename K, typename V, typename A = char, typename B = char, typename C = char> 
+	template <typename K, typename V, typename H = std::hash<K>, typename C = std::equal_to<K>, typename A = StdGenAlloc<std::pair<const K, V>>> 
 	struct unordered_multimap 
 	struct unordered_multimap 
 	{ 
 	{ 
-		typedef typename std::unordered_multimap<K, V> type; 
+		typedef typename std::unordered_multimap<K, V, H, C, A> type; 
 	}; 
 	}; 
 
 
 	// TODO - Once VC2012 grows up and adds proper C++11 support, uncomment this
 	// TODO - Once VC2012 grows up and adds proper C++11 support, uncomment this

+ 1 - 1
CamelotUtility/Include/CmString.h

@@ -351,7 +351,7 @@ namespace CamelotFramework {
         Strings must not contain spaces since space is used as a delimiter in
         Strings must not contain spaces since space is used as a delimiter in
         the output.
         the output.
     */
     */
-    CM_UTILITY_EXPORT std::vector<CamelotFramework::String> parseStringVector(const String& val);
+    CM_UTILITY_EXPORT vector<CamelotFramework::String>::type parseStringVector(const String& val);
     /** Checks the String is a valid number value. */
     /** Checks the String is a valid number value. */
     CM_UTILITY_EXPORT bool isNumber(const String& val);
     CM_UTILITY_EXPORT bool isNumber(const String& val);
 	/** @} */
 	/** @} */

+ 5 - 5
CamelotUtility/Source/CmString.cpp

@@ -75,9 +75,9 @@ namespace CamelotFramework {
     }
     }
 
 
     //-----------------------------------------------------------------------
     //-----------------------------------------------------------------------
-    std::vector<CamelotFramework::String> StringUtil::split( const String& str, const String& delims, unsigned int maxSplits)
+    vector<CamelotFramework::String>::type StringUtil::split( const String& str, const String& delims, unsigned int maxSplits)
     {
     {
-        std::vector<CamelotFramework::String> ret;
+        vector<CamelotFramework::String>::type ret;
         // Pre-allocate some space for performance
         // Pre-allocate some space for performance
         ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case
         ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case
 
 
@@ -117,9 +117,9 @@ namespace CamelotFramework {
         return ret;
         return ret;
     }
     }
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	std::vector<CamelotFramework::String> StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits)
+	vector<CamelotFramework::String>::type StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits)
 	{
 	{
-        std::vector<CamelotFramework::String> ret;
+        vector<CamelotFramework::String>::type ret;
         // Pre-allocate some space for performance
         // Pre-allocate some space for performance
         ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case
         ret.reserve(maxSplits ? maxSplits+1 : 10);    // 10 is guessed capacity for most case
 
 
@@ -673,7 +673,7 @@ namespace CamelotFramework {
 			return defaultValue;
 			return defaultValue;
 	}
 	}
 	//-----------------------------------------------------------------------
 	//-----------------------------------------------------------------------
-	std::vector<CamelotFramework::String> parseStringVector(const String& val)
+	vector<CamelotFramework::String>::type parseStringVector(const String& val)
 	{
 	{
 		return StringUtil::split(val);
 		return StringUtil::split(val);
 	}
 	}

+ 11 - 0
Notes.txt

@@ -31,6 +31,17 @@ Potential optimizations:
    - See here how to avoid locks and stalls when updating just parts of a GUI buffer. In need to modify my mesh update code because it currently always updates 100% of the buffer.
    - See here how to avoid locks and stalls when updating just parts of a GUI buffer. In need to modify my mesh update code because it currently always updates 100% of the buffer.
   - Maybe get rid of CPU UI buffers completely.
   - Maybe get rid of CPU UI buffers completely.
  - UI shader resolution params for gui should be in a separate constant buffer
  - UI shader resolution params for gui should be in a separate constant buffer
+
+ Memory allocation critical areas:
+ - TextUtility a lot of allocs
+ - Binding gpu params. It gets copied in DeferredRenderContext
+ - GameObjectHandle often allocates its internal data
+ - ResourceHandle often allocates its internal data
+ - AsyncOp allocates  AsyncOpData internally
+ - Deserialization, a lot of temporary allocations going on - But how much impact on performance will allocations have considering this is probably limited by disk read?
+ - Creating SceneObjects and Components - I might want to pool them, as I suspect user might alloc many per frame
+ - Log logMsg
+
 ----------------------------------------------------------------------------------------------
 ----------------------------------------------------------------------------------------------
 More detailed thought out system descriptions:
 More detailed thought out system descriptions:
 
 

+ 8 - 60
TODO.txt

@@ -36,70 +36,18 @@ IMMEDIATE:
   - Add support for bold (and maybe italic) fonts in Font importer
   - Add support for bold (and maybe italic) fonts in Font importer
   - Add support to disable aliasing when importing font
   - Add support to disable aliasing when importing font
 
 
-Mem allocation related:
-Following the example of MemStack add:
- - MemRegion - Allows user to mark regions and then free entire regions at once (FrameAllocator would be another name for it)
- - MemPool - Uses bit masks for querying empty slots, using the fast bit compare operators from GEG2 book allocator. Also make sure slots are split into block so we can easily dismiss large portions of allocated elements.
-    - Instead of using bit compare use something smarter like in RTSmallAlloc
-	- Also I can't place SceneObjects in the pool, since they hold a vector to a varying amount of components
- - Implement RTSmallAlloc for use in shared_ptrs and handles/asyncop
- - Organize calls to CM_NEW/CM_DELETE/etc better
- - Add an allocation counter to the default allocator
+std::shared_ptr
+std::vector, map, set, unordered_map, unordered_set should all use an allocator. 
+ - Primarily so I can track allocations
 
 
-Allocation critical areas:
- - TextUtility does a massive amount of allocs
- - Binding gpu params. It gets copied in DeferredRenderContext
- - GameObjectHandle often allocates its internal data
- - ResourceHandle often allocates its internal data
- - AsyncOp allocates  AsyncOpData internally
- - Deserialization, a lot of temporary allocations going on - But how much impact on performance will allocations have considering this is probably limited by disk read?
- - Creating SceneObjects and Components - I might want to pool them, as I suspect user might alloc many per frame
- - Log logMsg
 
 
-SOLUTION to TextUtility allocation:
- TextLine & TextWord structs are allocated from a per-thread pool as needed (MemObjectPool)
- Array of TextLines in TextData, array of TextWords in TextLine, and array of CHAR_DESC in TextWord are also allocated using the pool allocator. (MemBlockPool)
-  - Although this pool allocator should allocate based on certain size and not data type, but is otherwise the same
-  - But this means the array doesn't grow one by one, and instead grows N elements at a time (depending on the pool block size we choose)
-  - WHEN the array needs to be resized I need to access a larger pool
-   - USe the BSR instruction to quickly determine the pool where to fit the data
-    - Add some guards to ensure that we update the BSR instruction if we ever move to another platform
+make sure to find all std:: calls and replace them with my own
 
 
-HIERARCHICAL POOL MEM BLOCK ALLOCATOR: - Attempt to implement outside of camelot and test for speed compared to CRT
-MemAlloc::alloc(size(128))
-{
-  int chunkIdx = log2(size(128)); 
+  Make CM_NEW more friendly?
+ Maybe a template instead of macro, with default allocation type?
+ Also CM_DELETE so I don't have to use BOOST_PP_COMMA and specify templates exactly when calling delete
 
 
-  if(chunkIdx > maxChunkIdx)
-    new UINT8[2^chunkIdx]; // Just alloc directly if its over some maximum  
-
-  if(!chunks[chunkIdx].hasEmptySpace) // Using SmallAlloc approach which is very fast
-     chunks[chunkIdx].addNewChunk(alloc(2^(std::min(maxChunkIdx, chunkIdx + log2(blocksPerChunk))))
-  return chunks[chunkIdx].alloc()
-}
-
-MemAlloc::dealloc(UINT8* data, size(128))
-{
-   int chunkIdx = log2(size(128)); 
-
-   if(chunkIdx > maxChunkIdx)
-      delete[] data;
-
-   chunk myChunk = findChunkForData(data, size) // Using the SmallAlloc approach which is very fast
-   myChunk.dealloc(data)
-   
-   if(myChunk.empty())
-   {
-      chunks.removeChunk(myChunk)
-      dealloc(myChunk.dataPtr, myChunk.size)
-   }
-}
-
-ALLOCATOR - When I try to allocate and cannot find a chunk, try a higher level chunk to see if it has any empty space (without immediately jumping multiple levels?)
-
- MAYBE I should have a MemoryManager class, which can be manually allocated per-thread and then just passed around to methods that need it
-  (like TextUtility). It can contain all the needed allocators - although it might be a bit too coupling as every class will use it. Plus it's hard to extend.
-   - Maybe the actual allocators exist on specific classes, but the allocators accept MemoryManager as input. It's cleaner solution than using enums I think.
+And when I'm adding allocators to SharedPtr attempt to get rid of ugly-ass custom deleters and make just one easier to use shared_ptr wrapper.
 
 
 -----------
 -----------