#include "memory.hpp" #include namespace mkvparser { namespace mem { namespace { struct MemFuncOverride { malloc_func_t m_malloc; free_func_t m_free; }; static MemFuncOverride g_mem_func; } void SetFunctions(malloc_func_t _mallocFunc, free_func_t _freeFunc) { g_mem_func.m_malloc = _mallocFunc; g_mem_func.m_free = _freeFunc; } void UnsetFunctions() { g_mem_func.m_malloc = 0; g_mem_func.m_free = 0; } void* Allocate(size_t _size) { if (g_mem_func.m_malloc) return g_mem_func.m_malloc(_size); return std::malloc(_size); } void Free(void* _ptr) { if (g_mem_func.m_free) g_mem_func.m_free(_ptr); else std::free(_ptr); } } // namespace mem } // namespace mkvparser