forked from msinilo/rdestl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer_allocator.h
48 lines (40 loc) · 997 Bytes
/
buffer_allocator.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef RDESTL_BUFFER_ALLOCATOR_H
#define RDESTL_BUFFER_ALLOCATOR_H
#include "rdestl_common.h"
namespace rde
{
// CONCEPT!
class buffer_allocator
{
public:
explicit buffer_allocator(const char* name, char* mem,
size_t bufferSize)
: m_name(name),
m_buffer(mem),
m_bufferTop(0),
m_bufferSize(bufferSize)
{
/**/
}
void* allocate(size_t bytes, int /*flags*/ = 0)
{
RDE_ASSERT(m_bufferTop + bytes <= m_bufferSize);
char* ret = m_buffer + m_bufferTop;
m_bufferTop += bytes;
return ret;
}
void deallocate(void* ptr, size_t /*bytes*/)
{
RDE_ASSERT(ptr == 0 || (ptr >= m_buffer && ptr < m_buffer + m_bufferSize));
sizeof(ptr);
}
const char* get_name() const { return m_name; }
private:
const char* m_name;
char* m_buffer;
size_t m_bufferTop;
size_t m_bufferSize;
};
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_BUFFER_ALLOCATOR_H