Skip to content

Commit

Permalink
Add allocator abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jul 6, 2024
1 parent 8e53227 commit 0ba4710
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/cdc/sys/Allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include "Heap.h"

namespace cdc
{
enum MemTag
{
kMemTagMisc,
kMemTagDebug,
kMemTagAlloc = 0xff
};

class Allocator
{
public:
struct Overhead
{
int m_alloc;
int m_allocDebug;
int m_pool;
int m_poolDebug;
};

virtual ~Allocator() = 0;
virtual int GetType() = 0;

virtual unsigned int GetAlignment() = 0;
virtual unsigned int MaxAllocSize() = 0;
virtual unsigned int GetPoolSize() = 0;
virtual void GetOverhead(Overhead* overhead) = 0;
virtual bool InAddressSpace(const void* ptr) = 0;
virtual bool IsAllocation(const void* ptr) = 0;
virtual bool IsAllocated(const void* ptr) = 0;
virtual unsigned int PtrSize(const void* ptr) = 0;

virtual bool CheckMemoryCorruption() = 0;
virtual bool CheckMemoryCorruption(const void* ptr) = 0;
virtual bool CheckMemoryLeaks() = 0;

virtual void* Alloc(unsigned int size, MemTag tag) = 0;
virtual void Free(void* ptr) = 0;
virtual bool IsEmpty() = 0;
virtual void* GetContext(void* prevContext) = 0;
virtual void* GetPtr(void* context) = 0;
};

class HeapAllocator : public Allocator
{
public:
virtual unsigned int GetMaxHeapSize() = 0;
virtual unsigned int GetPageSize() = 0;
virtual unsigned int GetTopAddress() = 0;
virtual unsigned int GetTotalAllocSize() = 0;

virtual void* AllocNoAbort(unsigned int size, MemTag tag) = 0;
virtual void* AllocAlign(unsigned int align, unsigned int size, MemTag tag) = 0;
virtual void* Realloc(void* ptr, unsigned int size) = 0;

virtual Heap* GetHeapImpl() = 0;
};
}
8 changes: 8 additions & 0 deletions src/cdc/sys/Heap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace cdc
{
class Heap
{
};
}

0 comments on commit 0ba4710

Please sign in to comment.