2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_SHARED_MEMHEAP_H
|
|
|
|
#define ENGINE_SHARED_MEMHEAP_H
|
2021-05-27 17:35:20 +00:00
|
|
|
|
|
|
|
#include <cstddef>
|
2010-05-29 07:25:38 +00:00
|
|
|
class CHeap
|
|
|
|
{
|
|
|
|
struct CChunk
|
|
|
|
{
|
|
|
|
char *m_pMemory;
|
|
|
|
char *m_pCurrent;
|
|
|
|
char *m_pEnd;
|
|
|
|
CChunk *m_pNext;
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// how large each chunk should be
|
2020-09-26 19:41:58 +00:00
|
|
|
CHUNK_SIZE = 1025 * 64,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CChunk *m_pCurrent;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Clear();
|
|
|
|
void NewChunk();
|
2021-05-27 17:35:20 +00:00
|
|
|
void *AllocateFromChunk(unsigned int Size, unsigned Alignment);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
CHeap();
|
|
|
|
~CHeap();
|
|
|
|
void Reset();
|
2021-05-27 17:35:20 +00:00
|
|
|
void *Allocate(unsigned Size, unsigned Alignment = alignof(std::max_align_t));
|
2022-03-06 15:45:12 +00:00
|
|
|
const char *StoreString(const char *pSrc);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
#endif
|