CppCommon  1.0.4.1
C++ Common Library
allocator_null.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_MEMORY_ALLOCATOR_NULL_H
10 #define CPPCOMMON_MEMORY_ALLOCATOR_NULL_H
11 
12 #include "allocator.h"
13 
14 namespace CppCommon {
15 
17 
24 {
25 public:
26  NullMemoryManager() noexcept : _allocated(0), _allocations(0) {}
29  ~NullMemoryManager() noexcept { reset(); }
30 
33 
35  size_t allocated() const noexcept { return _allocated; }
37  size_t allocations() const noexcept { return _allocations; }
38 
40  size_t max_size() const noexcept { return std::numeric_limits<size_t>::max(); }
41 
43 
48  void* malloc(size_t size, size_t alignment = alignof(std::max_align_t));
50 
54  void free(void* ptr, size_t size);
55 
57  void reset();
58 
59 private:
60  // Allocation statistics
61  size_t _allocated;
62  size_t _allocations;
63 };
64 
66 template <typename T, bool nothrow = false>
68 
69 } // namespace CppCommon
70 
71 #include "allocator_null.inl"
72 
73 #endif // CPPCOMMON_MEMORY_ALLOCATOR_NULL_H
Memory allocator definition.
Null memory allocator inline implementation.
Memory allocator class.
Definition: allocator.h:25
Null memory manager class.
void reset()
Reset the memory manager.
size_t max_size() const noexcept
Maximum memory block size, that could be allocated by the memory manager.
size_t allocations() const noexcept
Count of active memory allocations.
void free(void *ptr, size_t size)
Free the previously allocated memory block.
NullMemoryManager & operator=(NullMemoryManager &&)=delete
NullMemoryManager(NullMemoryManager &&)=delete
NullMemoryManager & operator=(const NullMemoryManager &)=delete
NullMemoryManager(const NullMemoryManager &)=delete
size_t allocated() const noexcept
Allocated memory in bytes.
void * malloc(size_t size, size_t alignment=alignof(std::max_align_t))
Allocate a new memory block of the given size.
C++ Common project definitions.
Definition: token_bucket.h:15