CppCommon  1.0.4.1
C++ Common Library
allocator_heap.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_MEMORY_ALLOCATOR_HEAP_H
10 #define CPPCOMMON_MEMORY_ALLOCATOR_HEAP_H
11 
12 #include "allocator.h"
13 
14 #if defined(_WIN32) || defined(_WIN64)
15 #include <windows.h>
16 #undef DELETE
17 #undef ERROR
18 #undef Yield
19 #undef min
20 #undef max
21 #undef uuid_t
22 #endif
23 
24 namespace CppCommon {
25 
27 
35 {
36 public:
37  HeapMemoryManager() noexcept : _allocated(0), _allocations(0) {}
40  ~HeapMemoryManager() noexcept { reset(); }
41 
44 
46  size_t allocated() const noexcept { return _allocated; }
48  size_t allocations() const noexcept { return _allocations; }
49 
51  size_t max_size() const noexcept { return std::numeric_limits<size_t>::max(); }
52 
54 
59  void* malloc(size_t size, size_t alignment = alignof(std::max_align_t));
61 
65  void free(void* ptr, size_t size);
66 
68  void reset();
69 
70 private:
71  // Allocation statistics
72  size_t _allocated;
73  size_t _allocations;
74 };
75 
77 template <typename T, bool nothrow = false>
79 
80 } // namespace CppCommon
81 
82 #include "allocator_heap.inl"
83 
84 #endif // CPPCOMMON_MEMORY_ALLOCATOR_HEAP_H
Memory allocator definition.
Heap memory allocator inline implementation.
Memory allocator class.
Definition: allocator.h:25
Heap memory manager class.
size_t allocated() const noexcept
Allocated memory in bytes.
void reset()
Reset the memory manager.
HeapMemoryManager & operator=(const HeapMemoryManager &)=delete
size_t max_size() const noexcept
Maximum memory block size, that could be allocated by the memory manager.
void * malloc(size_t size, size_t alignment=alignof(std::max_align_t))
Allocate a new memory block of the given size.
HeapMemoryManager & operator=(HeapMemoryManager &&)=delete
HeapMemoryManager(HeapMemoryManager &&)=delete
HeapMemoryManager(const HeapMemoryManager &)=delete
size_t allocations() const noexcept
Count of active memory allocations.
void free(void *ptr, size_t size)
Free the previously allocated memory block.
C++ Common project definitions.
Definition: token_bucket.h:15