// Copyright (C) 2004-2009 Christoph Kubisch & Eike Decker
// This file is part of the "Luxinia Engine".
// For conditions of distribution and use, see copyright notice in luxiniapublicsdk.txt

#include <luxcore/memorybase.h>


//////////////////////////////////////////////////////////////////////////
//
#if 0

static int32 l_allocCnt = 0;

static void*	debugmalloc(size_t size)
{
	void* ptr = malloc(size);
	l_allocCnt++;

	return ptr;
}
static void*	debugcalloc(size_t size, size_t cnt)
{
	void* ptr =	calloc(size,cnt);
	l_allocCnt++;

	return ptr;
}
static void*	debugrealloc(void* ptr, size_t size)
{
	ptr = realloc(ptr,size);

	return ptr;
}
static void	debugfree(void* ptr)
{
	free(ptr);
	l_allocCnt--;
}


MemAllocator_t	g_MemAllocator = {
	debugmalloc,debugcalloc,debugrealloc,debugfree,
};
#else

#ifdef MEMORY_GLOBAL_DLMALLOC
#include <luxcore/memorydlmalloc.h>
lxMemAllocator_t	g_MemAllocator = {
	dlmalloc,dlcalloc,dlrealloc,dlfree,
};
#else
lxMemAllocator_t	g_MemAllocator = {
	malloc,calloc,realloc,free,
};
#endif
#endif
//////////////////////////////////////////////////////////////////////////
// Pointer



//////////////////////////////////////////////////////////////////////////
// Aligned alloc/free
void*	lxMemAlignedAlloc(size_t size, size_t align_size) 
{

	char *ptr=(char *)MEMORY_GLOBAL_MALLOC(size + align_size + sizeof(size_t));
	if(ptr==NULL) return(NULL);

	return(lxMemAlignedFromOrig(ptr,align_size));
}

void	lxMemAlignedFree(void *ptr) 
{
	MEMORY_GLOBAL_FREE(lxMemAlignedToOrig(ptr));
}
