-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtk_alloc.h
30 lines (22 loc) · 1.09 KB
/
tk_alloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
#include <stdlib.h>
#include <stdint.h>
namespace tk {
class IAllocator {
public:
virtual void* alloc( size_t size, uint64_t tag, const char *file, uint32_t line )=0;
virtual void* realloc( void *ptr, size_t size, uint64_t tag, const char *file, uint32_t line )=0;
virtual void free( void *ptr, const char *file, uint32_t line)=0;
};
// Default allocator that uses the system Malloc/Free
class DefaultAllocator : public IAllocator {
public:
virtual void* alloc( size_t size, uint64_t tag, const char *file, uint32_t line );
virtual void* realloc( void *ptr, size_t size, uint64_t tag, const char *file, uint32_t line );
virtual void free( void *ptr, const char *file, uint32_t line);
};
// Macros to use the allocator
#define TK_ALLOC( allocator, size, tag ) (allocator)->alloc( size, tag, __FILE__, __LINE__ )
#define TK_REALLOC( allocator, ptr, size, tag ) (allocator)->realloc( ptr, size, tag, __FILE__, __LINE__ )
#define TK_FREE( allocator, ptr, tag ) (allocator)->free( ptr, __FILE__, __LINE__ )
};