ROSE  0.11.96.11
DefaultAllocator.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_DefaultAllocator_H
9 #define Sawyer_DefaultAllocator_H
10 
11 #include <cstddef>
12 #include <Sawyer/Sawyer.h>
13 
14 namespace Sawyer {
15 
21 public:
27  void *allocate(size_t size) { // hot
28  return ::operator new(size);
29  }
30 
36  void deallocate(void *addr, size_t size) { // hot
37  SAWYER_ARGUSED(size);
38  ::operator delete(addr);
39  }
40 };
41 
59 template<class Allocator>
61  Allocator &allocator_;
62 public:
67  ProxyAllocator(Allocator &allocator): allocator_(allocator) {} // implicit
68 
74  void *allocate(size_t size) { return allocator_.allocate(size); }
75 
81  void deallocate(void *addr, size_t size) { allocator_.deallocate(addr, size); }
82 };
83 
84 } // namespace
85 
86 #endif
Sawyer::DefaultAllocator::allocate
void * allocate(size_t size)
Allocate memory.
Definition: DefaultAllocator.h:27
Sawyer::ProxyAllocator::deallocate
void deallocate(void *addr, size_t size)
Deallocate memory.
Definition: DefaultAllocator.h:81
Sawyer::ProxyAllocator
Allocator proxy.
Definition: DefaultAllocator.h:60
Sawyer::ProxyAllocator::allocate
void * allocate(size_t size)
Allocate memory.
Definition: DefaultAllocator.h:74
Sawyer::ProxyAllocator::ProxyAllocator
ProxyAllocator(Allocator &allocator)
Constructor.
Definition: DefaultAllocator.h:67
Sawyer
Name space for the entire library.
Definition: Access.h:13
Sawyer::DefaultAllocator
Default allocator.
Definition: DefaultAllocator.h:20
Sawyer::DefaultAllocator::deallocate
void deallocate(void *addr, size_t size)
Deallocate memory.
Definition: DefaultAllocator.h:36