#include <assert.h>

#include "../../Core/Memory/RuMemoryManager.h"

#ifdef new
	#undef new
#endif

#pragma unmanaged

#ifdef RUINCLUDE_MEMORYMANAGER

	void *operator new(size_t size)
	{
		return operator new(size, CRuMemoryHeapFactory::GetDefaultHeap());
	}

	void *operator new(size_t size, CRuMemoryHeap *heap)
	{
		assert(heap != NULL);
		return heap->Allocate(size);
	}

	void operator delete(void *mem)
	{
		if(mem != NULL)	
			CRuMemoryHeap::Deallocate(mem);
	}

	void *operator new[](size_t size)
	{
		return operator new[](size, CRuMemoryHeapFactory::GetDefaultHeap());
	}

	void *operator new[](size_t size, CRuMemoryHeap *heap)
	{
		assert(heap != NULL);
		return heap->Allocate(size);
	}

	void operator delete[](void *mem)
	{
		if(mem != NULL)	
			CRuMemoryHeap::Deallocate(mem);
	}

#else

#endif

#pragma managed
