Browse Source

More allocation porting

Marko Pintera 12 years ago
parent
commit
8f95f0a87d

+ 1 - 1
BansheeEngine/Include/BsCameraRTTI.h

@@ -29,7 +29,7 @@ namespace BansheeEngine
 
 		virtual std::shared_ptr<CM::IReflectable> newRTTIObject()
 		{
-			return std::shared_ptr<Camera>(CM_NEW(Camera, CM::PoolAlloc) Camera(), &CM::MemAllocDeleter<Camera, CM::PoolAlloc>::deleter);
+			return CM::cm_shared_ptr<Camera, CM::PoolAlloc>(new (CM::cm_alloc<Camera, CM::PoolAlloc>()) Camera());
 		}
 	};
 }

+ 2 - 1
BansheeEngine/Include/BsGUIArea.h

@@ -7,6 +7,8 @@ namespace BansheeEngine
 	class BS_EXPORT GUIArea
 	{
 	public:
+		~GUIArea();
+
 		/**
 		 * @brief	Sets up a new GUI area. All the layouts used in the area will be placed
 		 * 			within the specified bounds.
@@ -35,7 +37,6 @@ namespace BansheeEngine
 		GUILayout* mLayout;
 
 		GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth);
-		~GUIArea();
 
 		bool isDirty() const;
 

+ 1 - 2
BansheeEngine/Include/BsRenderableRTTI.h

@@ -29,8 +29,7 @@ namespace BansheeEngine
 
 		virtual std::shared_ptr<CM::IReflectable> newRTTIObject()
 		{
-			return std::shared_ptr<Renderable>(CM_NEW(Renderable, CM::PoolAlloc) Renderable(),
-				&CM::MemAllocDeleter<Renderable, CM::PoolAlloc>::deleter);
+			return CM::cm_shared_ptr<Renderable, CM::PoolAlloc>(new (CM::cm_alloc<Renderable, CM::PoolAlloc>()) Renderable());
 		}
 	};
 }

+ 1 - 2
BansheeEngine/Source/BsCamera.cpp

@@ -93,8 +93,7 @@ namespace BansheeEngine
 	{
 		target->waitUntilInitialized();
 
-		mViewport = ViewportPtr(CM_NEW(Viewport, PoolAlloc) Viewport(target, left, top, width, height, ZOrder),
-			&MemAllocDeleter<Viewport, PoolAlloc>::deleter);
+		mViewport = cm_shared_ptr<Viewport, PoolAlloc>(target, left, top, width, height, ZOrder);
 	}
 	//-----------------------------------------------------------------------
 	void Camera::setFOVy(const Radian& fov)

+ 2 - 2
BansheeEngine/Source/BsDebugDraw.cpp

@@ -81,8 +81,8 @@ namespace BansheeEngine
 		}
 
 		// TODO - Somehow avoid creating these every frame?
-		MeshDataPtr lineMeshData(CM_NEW(MeshData, ScratchAlloc) MeshData(totalNumLineVertices), &MemAllocDeleter<MeshData, ScratchAlloc>::deleter);
-		MeshDataPtr triangleMeshData(CM_NEW(MeshData, ScratchAlloc) MeshData(totalNumTriangleVertices), &MemAllocDeleter<MeshData, ScratchAlloc>::deleter);
+		MeshDataPtr lineMeshData = cm_shared_ptr<MeshData, ScratchAlloc>(totalNumLineVertices);
+		MeshDataPtr triangleMeshData = cm_shared_ptr<MeshData, ScratchAlloc>(totalNumTriangleVertices);
 
 		lineMeshData->beginDesc();
 

+ 3 - 3
BansheeEngine/Source/BsEngineGUI.cpp

@@ -61,7 +61,7 @@ namespace BansheeEngine
 		windowFrameTex.waitUntilLoaded();
 
 		GUIElementStyle windowFrameStyle;
-		windowFrameStyle.normal.texture = SpriteTexturePtr(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(windowFrameTex), &MemAllocDeleter<SpriteTexture, PoolAlloc>::deleter);
+		windowFrameStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(windowFrameTex);
 		windowFrameStyle.border.left = 1;
 		windowFrameStyle.border.right = 1;
 		windowFrameStyle.border.top = 1;
@@ -76,8 +76,8 @@ namespace BansheeEngine
 		buttonHoverTex.waitUntilLoaded();
 
 		GUIElementStyle buttonStyle;
-		buttonStyle.normal.texture = SpriteTexturePtr(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(buttonNormalTex), &MemAllocDeleter<SpriteTexture, PoolAlloc>::deleter);
-		buttonStyle.hover.texture = SpriteTexturePtr(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(buttonHoverTex), &MemAllocDeleter<SpriteTexture, PoolAlloc>::deleter);
+		buttonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(buttonNormalTex);
+		buttonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(buttonHoverTex);
 		buttonStyle.border.left = 5;
 		buttonStyle.border.right = 5;
 		buttonStyle.border.top = 5;

+ 5 - 5
BansheeEngine/Source/BsGUIArea.cpp

@@ -10,7 +10,7 @@ namespace BansheeEngine
 	GUIArea::GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth)
 		:mWidget(widget), mX(x), mY(y), mWidth(width), mHeight(height), mDepth(depth), mIsDirty(true)
 	{
-		mLayout = CM_NEW(GUILayoutX, PoolAlloc) GUILayoutX();
+		mLayout = cm_new<GUILayoutX, PoolAlloc>();
 
 		if(width <= 0)
 		{
@@ -29,24 +29,24 @@ namespace BansheeEngine
 
 	GUIArea::~GUIArea() 
 	{
-		CM_DELETE(mLayout, GUILayout, PoolAlloc);
+		cm_delete<PoolAlloc>(mLayout);
 	}
 
 	GUIArea* GUIArea::create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth)
 	{
-		return CM_NEW(GUIArea, PoolAlloc) GUIArea(widget, x, y, width, height, depth);
+		return new (cm_alloc<GUIArea, PoolAlloc>()) GUIArea(widget, x, y, width, height, depth);
 	}
 
 	void GUIArea::destroy(GUIArea* area)
 	{
 		area->mWidget.unregisterArea(area);
 
-		CM_DELETE(area, GUIArea, PoolAlloc);
+		cm_delete<PoolAlloc>(area);
 	}
 
 	void GUIArea::destroyInternal(GUIArea* area)
 	{
-		CM_DELETE(area, GUIArea, PoolAlloc);
+		cm_delete<PoolAlloc>(area);
 	}
 
 	void GUIArea::_update()

+ 6 - 6
BansheeEngine/Source/BsGUIButton.cpp

@@ -21,8 +21,8 @@ namespace BansheeEngine
 	GUIButton::GUIButton(GUIWidget& parent, const GUIElementStyle* style, const String& text, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, style, layoutOptions), mText(text), mNumImageRenderElements(0)
 	{
-		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
-		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
+		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
+		mTextSprite = cm_new<TextSprite, PoolAlloc>();
 
 		mImageDesc.texture = mStyle->normal.texture;
 
@@ -40,8 +40,8 @@ namespace BansheeEngine
 
 	GUIButton::~GUIButton()
 	{
-		CM_DELETE(mTextSprite, TextSprite, PoolAlloc);
-		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
+		cm_delete<PoolAlloc>(mTextSprite);
+		cm_delete<PoolAlloc>(mImageSprite);
 	}
 
 	GUIButton* GUIButton::create(GUIWidget& parent, const String& text, const GUIElementStyle* style)
@@ -52,7 +52,7 @@ namespace BansheeEngine
 			style = skin->getStyle(getGUITypeName());
 		}
 
-		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, style, text, getDefaultLayoutOptions(style));
+		return new (cm_alloc<GUIButton, PoolAlloc>()) GUIButton(parent, style, text, getDefaultLayoutOptions(style));
 	}
 
 	GUIButton* GUIButton::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
@@ -63,7 +63,7 @@ namespace BansheeEngine
 			style = skin->getStyle(getGUITypeName());
 		}
 
-		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, style, text, layoutOptions);
+		return new (cm_alloc<GUIButton, PoolAlloc>()) GUIButton(parent, style, text, layoutOptions);
 	}
 
 	UINT32 GUIButton::getNumRenderElements() const

+ 4 - 4
BansheeEngine/Source/BsGUILabel.cpp

@@ -13,7 +13,7 @@ namespace BansheeEngine
 	GUILabel::GUILabel(GUIWidget& parent, const GUIElementStyle* style, const String& text, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, style, layoutOptions), mText(text)
 	{
-		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
+		mTextSprite = cm_new<TextSprite, PoolAlloc>();
 
 		mDesc.text = text;
 		mDesc.font = mStyle->font;
@@ -25,7 +25,7 @@ namespace BansheeEngine
 
 	GUILabel::~GUILabel()
 	{
-		CM_DELETE(mTextSprite, TextSprite, PoolAlloc);
+		cm_delete<PoolAlloc>(mTextSprite);
 	}
 
 	UINT32 GUILabel::getNumRenderElements() const
@@ -116,7 +116,7 @@ namespace BansheeEngine
 			style = skin->getStyle(getGUITypeName());
 		}
 
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, style, text, getDefaultLayoutOptions(style));
+		return new (cm_alloc<GUILabel, PoolAlloc>()) GUILabel(parent, style, text, getDefaultLayoutOptions(style));
 	}
 
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
@@ -127,7 +127,7 @@ namespace BansheeEngine
 			style = skin->getStyle(getGUITypeName());
 		}
 
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, style, text, layoutOptions);
+		return new (cm_alloc<GUILabel, PoolAlloc>()) GUILabel(parent, style, text, layoutOptions);
 	}
 
 	const String& GUILabel::getGUITypeName()

+ 13 - 13
BansheeEngine/Source/BsGUILayout.cpp

@@ -22,15 +22,15 @@ namespace BansheeEngine
 			if(child.isLayout())
 			{
 				// Child layouts are directly owned by us
-				CM_DELETE(child.layout, GUILayout, PoolAlloc);
+				cm_delete<PoolAlloc>(child.layout);
 			}
 			else if(child.isFixedSpace())
 			{
-				CM_DELETE(child.space, GUIFixedSpace, PoolAlloc);
+				cm_delete<PoolAlloc>(child.space);
 			}
 			else if(child.isFlexibleSpace())
 			{
-				CM_DELETE(child.flexibleSpace, GUIFlexibleSpace, PoolAlloc);
+				cm_delete<PoolAlloc>(child.flexibleSpace);
 			}
 			else
 			{
@@ -91,7 +91,7 @@ namespace BansheeEngine
 	GUILayout& GUILayout::addLayoutX()
 	{
 		GUILayoutEntry entry;
-		entry.setLayout(CM_NEW(GUILayoutX, PoolAlloc) GUILayoutX());
+		entry.setLayout(cm_new<GUILayoutX, PoolAlloc>());
 
 		mChildren.push_back(entry);
 		mIsDirty = true;
@@ -102,7 +102,7 @@ namespace BansheeEngine
 	GUILayout& GUILayout::addLayoutY()
 	{
 		GUILayoutEntry entry;
-		entry.setLayout(CM_NEW(GUILayoutY, PoolAlloc) GUILayoutY());
+		entry.setLayout(cm_new<GUILayoutY, PoolAlloc>());
 
 		mChildren.push_back(entry);
 		mIsDirty = true;
@@ -138,7 +138,7 @@ namespace BansheeEngine
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutEntry entry;
-		entry.setLayout(CM_NEW(GUILayoutX, PoolAlloc) GUILayoutX());
+		entry.setLayout(cm_new<GUILayoutX, PoolAlloc>());
 
 		mChildren.insert(mChildren.begin() + idx, entry);
 		mIsDirty = true;
@@ -152,7 +152,7 @@ namespace BansheeEngine
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutEntry entry;
-		entry.setLayout(CM_NEW(GUILayoutY, PoolAlloc) GUILayoutY());;
+		entry.setLayout(cm_new<GUILayoutY, PoolAlloc>());;
 
 		mChildren.insert(mChildren.begin() + idx, entry);
 		mIsDirty = true;
@@ -163,7 +163,7 @@ namespace BansheeEngine
 	GUIFixedSpace& GUILayout::addSpace(UINT32 size)
 	{
 		GUILayoutEntry entry;
-		entry.setSpace(CM_NEW(GUIFixedSpace, PoolAlloc) GUIFixedSpace(size));
+		entry.setSpace(cm_new<GUIFixedSpace, PoolAlloc>(size));
 
 		mChildren.push_back(entry);
 		mIsDirty = true;
@@ -180,7 +180,7 @@ namespace BansheeEngine
 
 			if(child.isFixedSpace() && child.space == &space)
 			{
-				CM_DELETE(child.space, GUIFixedSpace, PoolAlloc);
+				cm_delete<PoolAlloc>(child.space);
 
 				mChildren.erase(iter);
 				foundElem = true;
@@ -199,7 +199,7 @@ namespace BansheeEngine
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutEntry entry;
-		entry.setSpace(CM_NEW(GUIFixedSpace, PoolAlloc) GUIFixedSpace(size));
+		entry.setSpace(cm_new<GUIFixedSpace, PoolAlloc>(size));
 
 		mChildren.insert(mChildren.begin() + idx, entry);
 		mIsDirty = true;
@@ -210,7 +210,7 @@ namespace BansheeEngine
 	GUIFlexibleSpace& GUILayout::addFlexibleSpace()
 	{
 		GUILayoutEntry entry;
-		entry.setFlexibleSpace(CM_NEW(GUIFlexibleSpace, PoolAlloc) GUIFlexibleSpace());
+		entry.setFlexibleSpace(cm_new<GUIFlexibleSpace, PoolAlloc>());
 
 		mChildren.push_back(entry);
 		mIsDirty = true;
@@ -227,7 +227,7 @@ namespace BansheeEngine
 
 			if(child.isFlexibleSpace() && child.flexibleSpace == &space)
 			{
-				CM_DELETE(child.flexibleSpace, GUIFlexibleSpace, PoolAlloc);
+				cm_delete<PoolAlloc>(child.flexibleSpace);
 
 				mChildren.erase(iter);
 				foundElem = true;
@@ -246,7 +246,7 @@ namespace BansheeEngine
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutEntry entry;
-		entry.setFlexibleSpace(CM_NEW(GUIFlexibleSpace, PoolAlloc) GUIFlexibleSpace());
+		entry.setFlexibleSpace(cm_new<GUIFlexibleSpace, PoolAlloc>());
 
 		mChildren.insert(mChildren.begin() + idx, entry);
 		mIsDirty = true;

+ 1 - 2
BansheeEngine/Source/BsGUIManager.cpp

@@ -355,8 +355,7 @@ namespace BansheeEngine
 					}
 				}
 
-				MeshDataPtr meshData = std::shared_ptr<MeshData>(CM_NEW(MeshData, PoolAlloc) MeshData(group->numQuads * 4),
-					&MemAllocDeleter<MeshData, PoolAlloc>::deleter);
+				MeshDataPtr meshData = cm_shared_ptr<MeshData, PoolAlloc>(group->numQuads * 4);
 
 				meshData->beginDesc();
 				meshData->addVertElem(VET_FLOAT2, VES_POSITION);

+ 1 - 1
BansheeEngine/Source/BsSpriteTexture.cpp

@@ -31,7 +31,7 @@ namespace BansheeEngine
 
 		if(!initialized)
 		{
-			dummyTex = SpriteTexturePtr(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(Texture::dummy()));
+			dummyTex = cm_shared_ptr<SpriteTexture, PoolAlloc>(Texture::dummy());
 		}
 
 		return dummyTex;

+ 1 - 1
BansheeForwardRenderer/Source/BsForwardRendererFactory.cpp

@@ -8,7 +8,7 @@ namespace BansheeEngine
 {
 	RendererPtr ForwardRendererFactory::create()
 	{
-		return RendererPtr(CM_NEW(ForwardRenderer, GenAlloc) ForwardRenderer(), &MemAllocDeleter<ForwardRenderer, GenAlloc>::deleter);
+		return cm_shared_ptr<ForwardRenderer>();
 	}
 
 	const std::string& ForwardRendererFactory::name() const

+ 1 - 3
BansheeForwardRenderer/Source/BsForwardRendererPlugin.cpp

@@ -13,9 +13,7 @@ namespace BansheeEngine
 
 	extern "C" BS_FWDRND_EXPORT void* loadPlugin()
 	{
-		RendererManager::instance().registerFactory(
-			RendererFactoryPtr(CM_NEW(ForwardRendererFactory, GenAlloc) ForwardRendererFactory(),
-			&MemAllocDeleter<ForwardRendererFactory, GenAlloc>::deleter));
+		RendererManager::instance().registerFactory(cm_shared_ptr<ForwardRendererFactory>());
 
 		return nullptr;
 	}

+ 1 - 1
BansheeOctreeSM/Source/BsSceneManagerPlugin.cpp

@@ -13,6 +13,6 @@ namespace BansheeEngine
 
 	extern "C" BS_SM_EXPORT void* loadPlugin()
 	{
-		return CM_NEW(OctreeSceneManager, GenAlloc) OctreeSceneManager();
+		return cm_new<OctreeSceneManager>();
 	}
 }

+ 1 - 2
CamelotCore/Include/CmResourcesRTTI.h

@@ -23,8 +23,7 @@ namespace CamelotFramework
 
 		virtual std::shared_ptr<IReflectable> newRTTIObject() 
 		{
-			return std::shared_ptr<Resources::ResourceMetaData>(CM_NEW(Resources::ResourceMetaData, PoolAlloc) Resources::ResourceMetaData(),
-				&MemAllocDeleter<Resources::ResourceMetaData, PoolAlloc>::deleter);
+			return cm_shared_ptr<Resources::ResourceMetaData, PoolAlloc>();
 		}
 
 		virtual const String& getRTTIName() 

+ 2 - 2
CamelotCore/Source/CmFontManager.cpp

@@ -5,7 +5,7 @@ namespace CamelotFramework
 {
 	FontPtr FontManager::create(vector<FontData>::type& fontData) const
 	{
-		FontPtr newFont(CM_NEW(Font, PoolAlloc) Font(), &CoreObject::_deleteDelayed<Font, PoolAlloc>);
+		FontPtr newFont = cm_core_ptr<Font, PoolAlloc>(new (cm_alloc<Font, PoolAlloc>()) Font());
 		newFont->setThisPtr(newFont);
 		newFont->initialize(fontData);
 
@@ -14,7 +14,7 @@ namespace CamelotFramework
 
 	FontPtr FontManager::createEmpty() const
 	{
-		FontPtr newFont(CM_NEW(Font, PoolAlloc) Font(), &CoreObject::_deleteDelayed<Font, PoolAlloc>);
+		FontPtr newFont = cm_core_ptr<Font, PoolAlloc>(new (cm_alloc<Font, PoolAlloc>()) Font());
 		newFont->setThisPtr(newFont);
 
 		return newFont;

+ 4 - 4
CamelotCore/Source/CmHighLevelGpuProgramManager.cpp

@@ -80,23 +80,23 @@ namespace CamelotFramework {
 		HighLevelGpuProgramPtr create(const String& source, const String& entryPoint, 
 			GpuProgramType gptype, GpuProgramProfile profile, const vector<HGpuProgInclude>::type* includes)
 		{
-			return HighLevelGpuProgramPtr(CM_NEW(NullProgram, PoolAlloc) NullProgram(), &CoreObject::_deleteDelayed<NullProgram, PoolAlloc>);
+			return cm_core_ptr<NullProgram, PoolAlloc>();
 		}
 		HighLevelGpuProgramPtr create()
 		{
-			return HighLevelGpuProgramPtr(CM_NEW(NullProgram, PoolAlloc) NullProgram(), &CoreObject::_deleteDelayed<NullProgram, PoolAlloc>);
+			return cm_core_ptr<NullProgram, PoolAlloc>();
 		}
 	};
 	//-----------------------------------------------------------------------
 	HighLevelGpuProgramManager::HighLevelGpuProgramManager()
 	{
-		mNullFactory = CM_NEW(NullProgramFactory, GenAlloc) NullProgramFactory();
+		mNullFactory = cm_new<NullProgramFactory>();
 		addFactory(mNullFactory);
 	}
 	//-----------------------------------------------------------------------
 	HighLevelGpuProgramManager::~HighLevelGpuProgramManager()
 	{
-		CM_DELETE((NullProgramFactory*)mNullFactory, NullProgramFactory, GenAlloc);
+		cm_delete((NullProgramFactory*)mNullFactory);
 	}
     //---------------------------------------------------------------------------
 	void HighLevelGpuProgramManager::addFactory(HighLevelGpuProgramFactory* factory)

+ 1 - 1
CamelotUtility/Include/CmAsyncOp.h

@@ -27,7 +27,7 @@ namespace CamelotFramework
 
 	public:
 		AsyncOp()
-			:mData(CM_NEW(AsyncOpData, ScratchAlloc) AsyncOpData(), &MemAllocDeleter<AsyncOpData, ScratchAlloc>::deleter)
+			:mData(cm_shared_ptr<AsyncOpData, ScratchAlloc>())
 		{}
 
 		/**

+ 30 - 4
CamelotUtility/Include/CmStdHeaders.h

@@ -207,23 +207,49 @@ namespace CamelotFramework
 		typedef typename std::unordered_multimap<K, V, H, C, A> type; 
 	}; 
 
+	//// Create a new shared pointer with a custom allocator category
+	// Implementation for 0-5 parameters uses allocate_shared
 #define MAKE_CM_NEW_SHARED(z, n, unused)                                     \
-	template<class Type, class category BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
+	template<class Type, class AllocCategory BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
 	std::shared_ptr<Type> cm_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) { \
-	return std::allocate_shared<Type>(StdAlloc<category>() BOOST_PP_ENUM_TRAILING_PARAMS (n, t));     \
+	return std::allocate_shared<Type>(StdAlloc<AllocCategory>() BOOST_PP_ENUM_TRAILING_PARAMS (n, t));     \
 	}
 
-	BOOST_PP_REPEAT(15, MAKE_CM_NEW_SHARED, ~)
+	BOOST_PP_REPEAT_FROM_TO(0, 6, MAKE_CM_NEW_SHARED, ~)
 
 #undef MAKE_CM_NEW_SHARED
 
+	// Implementation for more than 5 params uses shared_ptr constructor as allocate_shared only accepts up to 5 params
+#define MAKE_CM_NEW_SHARED(z, n, unused)                                     \
+	template<class Type, class AllocCategory BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
+	std::shared_ptr<Type> cm_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) { \
+	return std::shared_ptr<Type>(cm_new<Type, AllocCategory>(BOOST_PP_ENUM_PARAMS (n, t)), &cm_delete<AllocCategory, Type>, StdAlloc<AllocCategory>());     \
+	}
+
+	BOOST_PP_REPEAT_FROM_TO(6, 15, MAKE_CM_NEW_SHARED, ~)
+
+#undef MAKE_CM_NEW_SHARED
+
+	//// Create a new shared pointer with a general allocator category
+	// Implementation for 0-5 parameters uses allocate_shared
 #define MAKE_CM_NEW_SHARED(z, n, unused)                                     \
 	template<class Type BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
 	std::shared_ptr<Type> cm_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) { \
 	return std::allocate_shared<Type>(StdAlloc<GenAlloc>() BOOST_PP_ENUM_TRAILING_PARAMS (n, t));     \
 	}
 
-	BOOST_PP_REPEAT(15, MAKE_CM_NEW_SHARED, ~)
+	BOOST_PP_REPEAT_FROM_TO(0, 6, MAKE_CM_NEW_SHARED, ~)
+
+#undef MAKE_CM_NEW_SHARED
+
+	// Implementation for more than 5 params uses shared_ptr constructor as allocate_shared only accepts up to 5 params
+#define MAKE_CM_NEW_SHARED(z, n, unused)                                     \
+	template<class Type BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
+	std::shared_ptr<Type> cm_shared_ptr(BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) { \
+	return std::shared_ptr<Type>(cm_new<Type, GenAlloc>(BOOST_PP_ENUM_PARAMS (n, t)), &cm_delete<GenAlloc, Type>, StdAlloc<GenAlloc>());     \
+	}
+
+	BOOST_PP_REPEAT_FROM_TO(6, 15, MAKE_CM_NEW_SHARED, ~)
 
 #undef MAKE_CM_NEW_SHARED
 

+ 4 - 8
CamelotUtility/Source/CmFileSystem.cpp

@@ -45,15 +45,13 @@ namespace CamelotFramework
 		if (!readOnly)
 		{
 			mode |= std::ios::out;
-			rwStream = std::shared_ptr<std::fstream>(CM_NEW(std::fstream, ScratchAlloc) std::fstream(),
-				&MemAllocDeleter<std::fstream, ScratchAlloc>::deleter);
+			rwStream = cm_shared_ptr<std::fstream, ScratchAlloc>();
 			rwStream->open(fullPath.c_str(), mode);
 			baseStream = rwStream;
 		}
 		else
 		{
-			roStream = std::shared_ptr<std::ifstream>(CM_NEW(std::ifstream, ScratchAlloc) std::ifstream(),
-				&MemAllocDeleter<std::ifstream, ScratchAlloc>::deleter);
+			roStream = cm_shared_ptr<std::ifstream, ScratchAlloc>();
 			roStream->open(fullPath.c_str(), mode);
 			baseStream = roStream;
 		}
@@ -82,8 +80,7 @@ namespace CamelotFramework
 		// Always open in binary mode
 		// Also, always include reading
 		std::ios::openmode mode = std::ios::out | std::ios::binary;
-		std::shared_ptr<std::fstream> rwStream(CM_NEW(std::fstream, ScratchAlloc) std::fstream(),
-			&MemAllocDeleter<std::fstream, ScratchAlloc>::deleter);
+		std::shared_ptr<std::fstream> rwStream = cm_shared_ptr<std::fstream, ScratchAlloc>();
 		rwStream->open(fullPath.c_str(), mode);
 
 		// Should check ensure open succeeded, in case fail for some reason.
@@ -91,8 +88,7 @@ namespace CamelotFramework
 			CM_EXCEPT(FileNotFoundException, "Cannot open file: " + fullPath);
 
 		/// Construct return stream, tell it to delete on destroy
-		FileDataStream* stream = CM_NEW(FileDataStream, ScratchAlloc) FileDataStream(fullPath, rwStream, 0, true);
-		return DataStreamPtr(stream, &MemAllocDeleter<FileDataStream, ScratchAlloc>::deleter);
+		return cm_shared_ptr<FileDataStream, ScratchAlloc>(fullPath, rwStream, 0, true);
 	}
 
 	void FileSystem::remove(const String& fullPath)

+ 1 - 2
CamelotUtility/Source/CmWorkQueue.cpp

@@ -123,8 +123,7 @@ namespace CamelotFramework {
 			}
 		}
 		if (!duplicate)
-			handlers.push_back(RequestHandlerHolderPtr(CM_NEW(RequestHandlerHolder, GenAlloc) RequestHandlerHolder(rh),
-				&MemAllocDeleter<RequestHandlerHolder, GenAlloc>::deleter));
+			handlers.push_back(cm_shared_ptr<RequestHandlerHolder>(rh));
 
 	}
 	//---------------------------------------------------------------------