forked from msinilo/rdestl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocator.h
53 lines (41 loc) · 1.23 KB
/
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
49
50
51
52
53
#ifndef RDESTL_ALLOCATOR_H
#define RDESTL_ALLOCATOR_H
namespace rde
{
// CONCEPT!
class allocator
{
public:
explicit allocator(const char* name = "DEFAULT"): m_name(name) {}
allocator(const allocator&) = default;
allocator(allocator&&) = default;
~allocator() {}
allocator& operator=(const allocator&) = default;
void* allocate(unsigned int bytes, int flags = 0);
// Not supported for standard allocator for the time being.
void* allocate_aligned(unsigned int bytes, unsigned int alignment, int flags = 0);
void deallocate(void* ptr, unsigned int bytes);
const char* get_name() const;
private:
const char* m_name;
};
// True if lhs can free memory allocated by rhs and vice-versa.
inline bool operator==(const allocator& /*lhs*/, const allocator& /*rhs*/)
{
return true;
}
inline bool operator!=(const allocator& lhs, const allocator& rhs)
{
return !(lhs == rhs);
}
inline void* allocator::allocate(unsigned int bytes, int)
{
return operator new(bytes);
}
inline void allocator::deallocate(void* ptr, unsigned int)
{
operator delete(ptr);
}
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_ALLOCATOR_H