瀏覽代碼

Ported byte allocations to an easier to use system

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

+ 6 - 6
BansheeEngine/Source/BsDebugDraw.cpp

@@ -23,12 +23,12 @@ namespace BansheeEngine
 
 	void DebugDraw::draw2DLine(const Vector2&a, const Vector2& b, const Color& color, float timeout)
 	{
-		UINT32* indices = CM_NEW_ARRAY(UINT32, 2, ScratchAlloc);
-		UINT8* vertices = CM_NEW_BYTES(2 * VertexSize, ScratchAlloc);
+		UINT32* indices = cm_newN<UINT32, ScratchAlloc>(2);
+		UINT8* vertices = (UINT8*)cm_alloc<ScratchAlloc>(2 * VertexSize);
 
 		DebugDrawCommand command;
-		command.indices = CM_NEW_ARRAY(UINT32, 2, ScratchAlloc);
-		command.vertices = CM_NEW_BYTES(2 * VertexSize, ScratchAlloc);
+		command.indices = cm_newN<UINT32, ScratchAlloc>(2);
+		command.vertices = (UINT8*)cm_alloc<ScratchAlloc>(2 * VertexSize);
 		command.numElements = 1;
 		command.type = DebugDrawType::Line;
 		command.timeEnds = gTime().getTime() + timeout;
@@ -150,8 +150,8 @@ namespace BansheeEngine
 					numIndices = command.numElements * 3;
 				}
 
-				CM_DELETE_ARRAY(command.indices, UINT32, numIndices, ScratchAlloc);
-				CM_DELETE_BYTES(command.vertices, ScratchAlloc);
+				cm_deleteN<ScratchAlloc>(command.indices, numIndices);
+				cm_free<ScratchAlloc>(command.vertices);
 			}
 		}
 

+ 1 - 1
CamelotCore/Include/CmMaterial.h

@@ -45,7 +45,7 @@ namespace CamelotFramework
 			StructData(void* _data, UINT32 _size)
 				:size(_size)
 			{
-				data = std::shared_ptr<void>(CM_NEW_BYTES(_size, ScratchAlloc), &cm_free<ScratchAlloc>);
+				data = std::shared_ptr<void>(cm_alloc<ScratchAlloc>(_size), &cm_free<ScratchAlloc>);
 				memcpy(data.get(), _data, size);
 			}
 

+ 3 - 3
CamelotCore/Source/CmGpuParamBlock.cpp

@@ -9,14 +9,14 @@ namespace CamelotFramework
 	GpuParamBlock::GpuParamBlock(UINT32 size)
 		:mDirty(true), mData(nullptr), mSize(size)
 	{
-		mData = CM_NEW_BYTES(mSize, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(mSize);
 		memset(mData, 0, mSize);
 	}
 
 	GpuParamBlock::GpuParamBlock(GpuParamBlock* otherBlock)
 	{
 		mSize = otherBlock->mSize;
-		mData = CM_NEW_BYTES(mSize, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(mSize);
 		write(0, otherBlock->getData(), otherBlock->getSize());
 		mDirty = otherBlock->mDirty;
 	}
@@ -24,7 +24,7 @@ namespace CamelotFramework
 	GpuParamBlock::~GpuParamBlock()
 	{
 		if(mData != nullptr)
-			CM_DELETE_BYTES(mData, ScratchAlloc);
+			cm_free<ScratchAlloc>(mData);
 	}
 
 	void GpuParamBlock::write(UINT32 offset, const void* data, UINT32 size)

+ 2 - 2
CamelotCore/Source/CmGpuParamBlockBuffer.cpp

@@ -33,7 +33,7 @@ namespace CamelotFramework
 
 	void GenericGpuParamBlockBuffer::initialize_internal()
 	{
-		mData = CM_NEW_BYTES(mSize, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(mSize);
 		memset(mData, 0, mSize);
 
 		GpuParamBlockBuffer::initialize_internal();
@@ -42,7 +42,7 @@ namespace CamelotFramework
 	void GenericGpuParamBlockBuffer::destroy_internal()
 	{
 		if(mData != nullptr)
-			CM_DELETE_BYTES(mData, ScratchAlloc);
+			cm_free<ScratchAlloc>(mData);
 
 		GpuParamBlockBuffer::destroy_internal();
 	}

+ 2 - 2
CamelotCore/Source/CmGpuResourceData.cpp

@@ -53,7 +53,7 @@ namespace CamelotFramework
 
 		freeInternalBuffer();
 
-		mData = CM_NEW_BYTES(size, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(size);
 		mOwnsData = true;
 	}
 
@@ -70,7 +70,7 @@ namespace CamelotFramework
 		}
 #endif
 
-		CM_DELETE_BYTES(mData, ScratchAlloc);
+		cm_free<ScratchAlloc>(mData);
 		mData = nullptr;
 	}
 

+ 4 - 4
CamelotD3D11RenderSystem/Source/CmD3D11Driver.cpp

@@ -85,26 +85,26 @@ namespace CamelotFramework
 	String D3D11Driver::getDriverName() const
 	{
 		size_t size = wcslen(mAdapterIdentifier.Description);
-		char* str = (char*)CM_NEW_BYTES((UINT32)(size + 1), ScratchAlloc);
+		char* str = (char*)cm_alloc<ScratchAlloc>((UINT32)(size + 1));
 
 		wcstombs(str, mAdapterIdentifier.Description, size);
 		str[size] = '\0';
 		String Description = str;
 		
-		CM_DELETE_BYTES(str, ScratchAlloc);
+		cm_free<ScratchAlloc>(str);
 		return String(Description );
 	}
 
 	String D3D11Driver::getDriverDescription() const
 	{
 		size_t size = wcslen(mAdapterIdentifier.Description);
-		char* str = (char*)CM_NEW_BYTES((UINT32)(size + 1), ScratchAlloc);
+		char* str = (char*)cm_alloc<ScratchAlloc>((UINT32)(size + 1));
 
 		wcstombs(str, mAdapterIdentifier.Description, size);
 		str[size] = '\0';
 		String driverDescription = str;
 
-		CM_DELETE_BYTES(str, ScratchAlloc);
+		cm_free<ScratchAlloc>(str);
 		StringUtil::trim(driverDescription);
 
 		return driverDescription;

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9IndexBuffer.cpp

@@ -63,7 +63,7 @@ namespace CamelotFramework {
 		mBufferDesc.Pool = eResourcePool;
 
 		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (char*) CM_NEW_BYTES(getSizeInBytes(), ScratchAlloc);
+		mSystemMemoryBuffer = (char*) cm_alloc<ScratchAlloc>(getSizeInBytes());
 		memset(mSystemMemoryBuffer, 0, getSizeInBytes());
 
 		// Case we have to create this buffer resource on loading.
@@ -98,7 +98,7 @@ namespace CamelotFramework {
 		mMapDeviceToBufferResources.clear();   
 
 		if(mSystemMemoryBuffer != nullptr)
-			CM_DELETE_BYTES(mSystemMemoryBuffer, ScratchAlloc);
+			cm_free<ScratchAlloc>(mSystemMemoryBuffer);
 
 		IndexBuffer::destroy_internal();
 	}

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9RenderSystem.cpp

@@ -382,7 +382,7 @@ namespace CamelotFramework
 			{
 				GpuParamBlockBufferPtr paramBlock = params.getParamBlockBuffer(paramBlockSlot);
 
-				UINT8* data = CM_NEW_BYTES(paramBlock->getSize(), ScratchAlloc);
+				UINT8* data = (UINT8*)cm_alloc<ScratchAlloc>(paramBlock->getSize());
 				paramBlock->readData(data);
 
 				bufferData[paramBlockSlot] = data;
@@ -499,7 +499,7 @@ namespace CamelotFramework
 
 		for(auto& curBufferData : bufferData)
 		{
-			CM_DELETE_BYTES(curBufferData.second, ScratchAlloc);
+			cm_free<ScratchAlloc>(curBufferData.second);
 		}
 	}
 	//---------------------------------------------------------------------

+ 2 - 2
CamelotD3D9Renderer/Source/CmD3D9VertexBuffer.cpp

@@ -316,7 +316,7 @@ namespace CamelotFramework {
 		mBufferDesc.Pool = eResourcePool;
 
 		// Allocate the system memory buffer.
-		mSystemMemoryBuffer = (char*)CM_NEW_BYTES(getSizeInBytes(), ScratchAlloc);
+		mSystemMemoryBuffer = (char*)cm_alloc<ScratchAlloc>(getSizeInBytes());
 		memset(mSystemMemoryBuffer, 0, getSizeInBytes());	
 
 		// Case we have to create this buffer resource on loading.
@@ -351,7 +351,7 @@ namespace CamelotFramework {
 		mMapDeviceToBufferResources.clear();   
 
 		if(mSystemMemoryBuffer != nullptr)
-			CM_DELETE_BYTES(mSystemMemoryBuffer, ScratchAlloc);
+			cm_free<ScratchAlloc>(mSystemMemoryBuffer);
 
 		VertexBuffer::destroy_internal();
 	}

+ 2 - 2
CamelotFreeImgImporter/Source/CmTextureData.cpp

@@ -9,13 +9,13 @@ namespace CamelotFramework
 		mFlags(flags), mNumMipmaps(numMipmaps)
 	{
 		mBPP = static_cast<UINT8>(PixelUtil::getNumElemBytes(mFormat)) * 8;
-		mData = CM_NEW_BYTES(size, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(size);
 	}
 
 	TextureData::~TextureData()
 	{
 		if(mData != nullptr)
-			CM_DELETE_BYTES(mData, ScratchAlloc);
+			cm_free<ScratchAlloc>(mData);
 	}
 
 	PixelData TextureData::getPixels(UINT32 mip)

+ 2 - 2
CamelotGLRenderer/Source/CmGLRenderSystem.cpp

@@ -352,7 +352,7 @@ namespace CamelotFramework
 				// 0 means uniforms are not in block, in which case we handle it specially
 				if(uniformBufferData == nullptr)
 				{
-					uniformBufferData = CM_NEW_BYTES(paramBlockBuffer->getSize(), ScratchAlloc);
+					uniformBufferData = (UINT8*)cm_alloc<ScratchAlloc>(paramBlockBuffer->getSize());
 					paramBlockBuffer->readData(uniformBufferData);
 				}
 
@@ -449,7 +449,7 @@ namespace CamelotFramework
 
 		if(uniformBufferData != nullptr)
 		{
-			CM_DELETE_BYTES(uniformBufferData, ScratchAlloc);
+			cm_free<ScratchAlloc>(uniformBufferData);
 		}
 	}
 	//-----------------------------------------------------------------------------

+ 4 - 4
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -150,7 +150,7 @@ namespace CamelotFramework {
 			GetMonitorInfo(hMonitor, &monitorInfoEx);
 
 			size_t devNameLen = strlen(monitorInfoEx.szDevice);
-			mDeviceName = (char*)CM_NEW_BYTES((UINT32)(devNameLen + 1), ScratchAlloc);
+			mDeviceName = (char*)cm_alloc<ScratchAlloc>((UINT32)(devNameLen + 1));
 
 			strcpy_s(mDeviceName, devNameLen + 1, monitorInfoEx.szDevice);
 
@@ -404,7 +404,7 @@ namespace CamelotFramework {
 
 		if (mDeviceName != NULL)
 		{
-			CM_DELETE_BYTES(mDeviceName, ScratchAlloc);
+			cm_free<ScratchAlloc>(mDeviceName);
 			mDeviceName = NULL;
 		}
 
@@ -661,7 +661,7 @@ namespace CamelotFramework {
 		{
 			size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.getFormat());
 			size_t height = dst.getHeight();
-			UINT8 *tmpData = CM_NEW_BYTES((UINT32)(rowSpan * height), ScratchAlloc);
+			UINT8 *tmpData = (UINT8*)cm_alloc<ScratchAlloc>((UINT32)(rowSpan * height));
 			UINT8 *srcRow = (UINT8 *)dst.getData(), *tmpRow = tmpData + (height - 1) * rowSpan;
 
 			while (tmpRow >= tmpData)
@@ -672,7 +672,7 @@ namespace CamelotFramework {
 			}
 			memcpy(dst.getData(), tmpData, rowSpan * height);
 
-			CM_DELETE_BYTES(tmpData, ScratchAlloc);
+			cm_free<ScratchAlloc>(tmpData);
 		}
 	}
 

+ 4 - 4
CamelotGLRenderer/Source/GLSL/include/CmGLSLParamParser.h

@@ -68,7 +68,7 @@ namespace CamelotFramework
 		GLint maxNameSize = 0;
 		glGetProgramiv(glProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameSize);
 
-		GLchar* attributeName = (GLchar*)CM_NEW_BYTES(sizeof(GLchar) * maxNameSize, ScratchAlloc);
+		GLchar* attributeName = (GLchar*)cm_alloc<ScratchAlloc>(sizeof(GLchar) * maxNameSize);
 
 		for(GLint i = 0; i < numAttributes; i++)
 		{
@@ -90,7 +90,7 @@ namespace CamelotFramework
 			}
 		}
 
-		CM_DELETE_BYTES(attributeName, ScratchAlloc);
+		cm_free<ScratchAlloc>(attributeName);
 	}
 
 	VertexElementType GLSLParamParser::glTypeToAttributeType(GLenum glType)
@@ -152,7 +152,7 @@ namespace CamelotFramework
 		if(maxBlockNameBufferSize > maxBufferSize)
 			maxBufferSize = maxBlockNameBufferSize;
 
-		GLchar* uniformName = (GLchar*)CM_NEW_BYTES(sizeof(GLchar) * maxBufferSize, ScratchAlloc);
+		GLchar* uniformName = (GLchar*)cm_alloc<ScratchAlloc>(sizeof(GLchar) * maxBufferSize);
 
 		GpuParamBlockDesc newGlobalBlockDesc;
 		newGlobalBlockDesc.slot = 0;
@@ -464,7 +464,7 @@ namespace CamelotFramework
 		}
 #endif
 
-		CM_DELETE_BYTES(uniformName, ScratchAlloc);
+		cm_free<ScratchAlloc>(uniformName);
 	}
 
 	void GLSLParamParser::determineParamInfo(GpuParamDataDesc& desc, const String& paramName, GLuint programHandle, GLuint uniformIndex)

+ 4 - 4
CamelotGLRenderer/Source/GLSL/src/CmGLSLExtSupport.cpp

@@ -95,12 +95,12 @@ namespace CamelotFramework
 			{
 				GLint charsWritten  = 0;
 
-				GLchar* infoLog = (GLchar*)CM_NEW_BYTES(sizeof(GLchar) * infologLength, ScratchAlloc);
+				GLchar* infoLog = (GLchar*)cm_alloc<ScratchAlloc>(sizeof(GLchar) * infologLength);
 
 				glGetShaderInfoLog(obj, infologLength, &charsWritten, infoLog);
 				logMessage += String(infoLog);
 
-				CM_DELETE_BYTES(infoLog, ScratchAlloc);
+				cm_free<ScratchAlloc>(infoLog);
 
 				if(charsWritten > 0)
 					return true;
@@ -122,12 +122,12 @@ namespace CamelotFramework
 			{
 				GLint charsWritten  = 0;
 
-				GLchar* infoLog = (GLchar*)CM_NEW_BYTES(sizeof(GLchar) * infologLength, ScratchAlloc);
+				GLchar* infoLog = (GLchar*)cm_alloc<ScratchAlloc>(sizeof(GLchar) * infologLength);
 
 				glGetProgramInfoLog(obj, infologLength, &charsWritten, infoLog);
 				msg += String(infoLog);
 
-				CM_DELETE_BYTES(infoLog, ScratchAlloc);
+				cm_free<ScratchAlloc>(infoLog);
 
 				if(charsWritten > 0)
 					return true;

+ 5 - 5
CamelotUtility/Include/CmMemStack.h

@@ -16,12 +16,12 @@ namespace CamelotFramework
 			MemBlock(UINT32 size)
 				:mData(nullptr), mFreePtr(0), mSize(size)
 			{
-				mData = static_cast<UINT8*>(CM_NEW_BYTES(mSize, GenAlloc));
+				mData = static_cast<UINT8*>(cm_alloc(mSize));
 			}
 
 			~MemBlock()
 			{
-				CM_DELETE_BYTES(mData, GenAlloc);
+				cm_free(mData);
 			}
 
 			UINT8* alloc(UINT8 amount)
@@ -56,7 +56,7 @@ namespace CamelotFramework
 				MemBlock* curPtr = mBlocks.top();
 				mBlocks.pop();
 
-				CM_DELETE(curPtr, MemBlock, GenAlloc);
+				cm_delete(curPtr);
 			}
 		}
 
@@ -90,7 +90,7 @@ namespace CamelotFramework
 
 			if(topBlock->mFreePtr == 0)
 			{
-				CM_DELETE(topBlock, MemBlock, GenAlloc);
+				cm_delete(topBlock);
 				mBlocks.pop();
 			}
 		}
@@ -105,7 +105,7 @@ namespace CamelotFramework
 			if(wantedSize > blockSize)
 				blockSize = wantedSize;
 
-			MemBlock* newBlock = CM_NEW(MemBlock, GenAlloc) MemBlock(blockSize);
+			MemBlock* newBlock = cm_new<MemBlock>(blockSize);
 			mBlocks.push(newBlock);
 
 			return newBlock;

+ 74 - 22
CamelotUtility/Include/CmMemoryAllocator.h

@@ -78,6 +78,27 @@ namespace CamelotFramework
 		MemoryAllocator<category>::freeArray(ptr, count);
 	}
 
+	/**
+	 * @brief	General allocator provided by the OS. Use for persistent long term allocations,
+	 * 			and allocations that don't happen often.
+	 */
+	class GenAlloc
+	{ };
+
+	/**
+	 * @brief	Allocator used for allocating small amounts of temporary memory that
+	 * 			used and then quickly released
+	 */
+	class ScratchAlloc
+	{ };
+
+	/**
+	 * @brief	Pool allocator that is only suited for allocating one specific type of data. Most useful when you are
+	 * 			often allocating one certain data type, with no specific allocation or deallocation order.
+	 */
+	class PoolAlloc
+	{ };
+
 	template<class category> 
 	inline void* cm_alloc(UINT32 count)
 	{
@@ -109,6 +130,8 @@ namespace CamelotFramework
 
 	BOOST_PP_REPEAT(9, MAKE_CM_NEW, ~)
 
+#undef MAKE_CM_NEW
+
 	template<class category> 
 	inline void cm_free(void* ptr)
 	{
@@ -132,33 +155,62 @@ namespace CamelotFramework
 		MemoryAllocator<category>::freeArray(ptr, count);
 	}
 
-	/**
-	 * @brief	General allocator provided by the OS. Use for persistent long term allocations,
-	 * 			and allocations that don't happen often.
-	 */
-	class GenAlloc
-	{ };
+	/*****************************************************************************/
+	/* Default versions of all alloc/free/new/delete methods which call GenAlloc */
+	/*****************************************************************************/
 
-	/**
-	 * @brief	Allocator used for allocating small amounts of temporary memory that
-	 * 			used and then quickly released
-	 */
-	class ScratchAlloc
-	{ };
+	inline void* cm_alloc(UINT32 count)
+	{
+		return MemoryAllocator<GenAlloc>::allocate(count);
+	}
 
-	/**
-	 * @brief	Pool allocator that is only suited for allocating one specific type of data. Most useful when you are
-	 * 			often allocating one certain data type, with no specific allocation or deallocation order.
-	 */
-	class PoolAlloc
-	{ };
+	template<class T> 
+	inline T* cm_newN(UINT32 count)
+	{
+		T* ptr = (T*)MemoryAllocator<GenAlloc>::allocateArray(sizeof(T), count);
+
+		for(unsigned int i = 0; i < count; i++)
+			new ((void*)&ptr[i]) T;
+
+		return ptr;
+	}
+
+#define MAKE_CM_NEW(z, n, unused)                                     \
+	template<class Type BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
+	Type* cm_new(BOOST_PP_ENUM_BINARY_PARAMS(n, T, t) ) { \
+	return new (cm_alloc<GenAlloc>(sizeof(Type))) Type(BOOST_PP_ENUM_PARAMS (n, t));     \
+	}
+
+	BOOST_PP_REPEAT(9, MAKE_CM_NEW, ~)
+
+#undef MAKE_CM_NEW
+
+	inline void cm_free(void* ptr)
+	{
+		MemoryAllocator<GenAlloc>::free(ptr);
+	}
+
+	template<class T> 
+	inline void cm_delete(T* ptr)
+	{
+		(ptr)->~T();
+
+		MemoryAllocator<GenAlloc>::free(ptr);
+	}
+
+	template<class T> 
+	inline void cm_deleteN(T* ptr, UINT32 count)
+	{
+		for(unsigned int i = 0; i < count; i++)
+			ptr[i].~T();
+
+		MemoryAllocator<GenAlloc>::freeArray(ptr, count);
+	}
 }
 
 #define CM_NEW(T, category) new (CamelotFramework::MemoryAllocator<category>::allocate(sizeof(T)))
-#define CM_NEW_BYTES(count, category) (UINT8*)CamelotFramework::MemoryAllocator<category>::allocate(count)
 #define CM_NEW_ARRAY(T, count, category) CamelotFramework::__cm_construct_array<T, category>(count)
 #define CM_DELETE(ptr, T, category) {(ptr)->~T(); 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_deleteN<category>(ptr, count)
 
 namespace CamelotFramework
@@ -219,7 +271,7 @@ namespace CamelotFramework
 		// 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), Category));
+			pointer ret = (pointer)(cm_alloc<Category>((UINT32)num*sizeof(T)));
 			return ret;
 		}
 
@@ -241,7 +293,7 @@ namespace CamelotFramework
 		void deallocate (pointer p, size_type num) 
 		{
 			// print message and deallocate memory with global delete
-			CM_DELETE_BYTES((void*)p, Category);
+			cm_free<Category>((void*)p);
 		}
 	};
 

+ 1 - 1
CamelotUtility/Include/CmRTTIManagedDataBlockField.h

@@ -77,7 +77,7 @@ namespace CamelotFramework
 		virtual UINT8* allocate(void* object, UINT32 bytes)
 		{
 			if(mCustomAllocator.empty())
-				return CM_NEW_BYTES(bytes, ScratchAlloc);
+				return (UINT8*)cm_alloc<ScratchAlloc>(bytes);
 			else
 			{
 				ObjectType* castObj = static_cast<ObjectType*>(object);

+ 2 - 2
CamelotUtility/Include/CmString.h

@@ -382,12 +382,12 @@ namespace CamelotFramework {
 			memory += sizeof(UINT32);
 
 			UINT32 stringSize = size - sizeof(UINT32);
-			char* buffer = (char*)CM_NEW_BYTES(stringSize + 1, ScratchAlloc);
+			char* buffer = (char*)cm_alloc<ScratchAlloc>(stringSize + 1);
 			memcpy(buffer, memory, stringSize); 
 			buffer[stringSize] = '\0';
 			data = String(buffer);
 
-			CM_DELETE_BYTES(buffer, ScratchAlloc);
+			cm_free<ScratchAlloc>(buffer);
 
 			return size;
 		}

+ 4 - 4
CamelotUtility/Source/CmFileSerializer.cpp

@@ -11,12 +11,12 @@ namespace CamelotFramework
 {
 	FileSerializer::FileSerializer()
 	{
-		mWriteBuffer = CM_NEW_BYTES(WRITE_BUFFER_SIZE, ScratchAlloc);
+		mWriteBuffer = (UINT8*)cm_alloc<ScratchAlloc>(WRITE_BUFFER_SIZE);
 	}
 
 	FileSerializer::~FileSerializer()
 	{
-		CM_DELETE_BYTES(mWriteBuffer, ScratchAlloc);
+		cm_free<ScratchAlloc>(mWriteBuffer);
 	}
 
 	void FileSerializer::encode(IReflectable* object, std::string fileLocation)
@@ -42,7 +42,7 @@ namespace CamelotFramework
 				"File size is larger that UINT32 can hold. Ask a programmer to use a bigger data type.");
 		}
 
-		UINT8* readBuffer = CM_NEW_BYTES((UINT32)fileSize, ScratchAlloc); // TODO - Low priority. Consider upgrading BinarySerializer so we don't have to read everything at once
+		UINT8* readBuffer = (UINT8*)cm_alloc<ScratchAlloc>((UINT32)fileSize); // TODO - Low priority. Consider upgrading BinarySerializer so we don't have to read everything at once
 
 		mInputStream.seekg(0, std::ios::beg);
 		mInputStream.read((char*)readBuffer, fileSize);
@@ -53,7 +53,7 @@ namespace CamelotFramework
 		mInputStream.close();
 		mInputStream.clear();
 
-		CM_DELETE_BYTES(readBuffer, ScratchAlloc);
+		cm_free<ScratchAlloc>(readBuffer);
 
 		return object;
 	}

+ 2 - 2
CamelotUtility/Source/CmManagedDataBlock.cpp

@@ -10,7 +10,7 @@ namespace CamelotFramework
 	ManagedDataBlock::ManagedDataBlock(UINT32 size)
 		:mSize(size), mManaged(true), mIsDataOwner(true)
 	{
-		mData = CM_NEW_BYTES(size, ScratchAlloc);
+		mData = (UINT8*)cm_alloc<ScratchAlloc>(size);
 	}
 
 	ManagedDataBlock::ManagedDataBlock(const ManagedDataBlock& source)
@@ -26,6 +26,6 @@ namespace CamelotFramework
 	ManagedDataBlock::~ManagedDataBlock()
 	{
 		if(mManaged && mIsDataOwner)
-			CM_DELETE_BYTES(mData, ScratchAlloc);
+			cm_free<ScratchAlloc>(mData);
 	}
 }