mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Lots of stuff
This commit is contained in:
51
PortabilityLayer/MemoryManager.h
Normal file
51
PortabilityLayer/MemoryManager.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#ifndef __PL_MEMORY_MANAGER_H__
|
||||
#define __PL_MEMORY_MANAGER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
|
||||
class MemoryManager
|
||||
{
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual void *Alloc(size_t size) = 0;
|
||||
virtual void Release(void *buf) = 0;
|
||||
|
||||
virtual MMHandleBlock *AllocHandle(size_t size) = 0;
|
||||
virtual void ReleaseHandle(MMHandleBlock *hdl) = 0;
|
||||
|
||||
template<class T>
|
||||
T **NewHandle();
|
||||
|
||||
static MemoryManager *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
#include <new>
|
||||
#include "CoreDefs.h"
|
||||
#include "MMHandleBlock.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
template<class T>
|
||||
T **MemoryManager::NewHandle()
|
||||
{
|
||||
MMHandleBlock *hdl = this->AllocHandle(sizeof(T));
|
||||
if (!hdl)
|
||||
return nullptr;
|
||||
|
||||
T **objectHdl = reinterpret_cast<T**>(hdl);
|
||||
T *objectPtr = *objectHdl;
|
||||
new (objectPtr) T();
|
||||
|
||||
return objectHdl;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user