CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
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
24namespace CppCommon {
25
27
35{
36public:
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
70private:
71 // Allocation statistics
72 size_t _allocated;
73 size_t _allocations;
74};
75
77template <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.
HeapMemoryManager & operator=(const HeapMemoryManager &)=delete
size_t allocated() const noexcept
Allocated memory in bytes.
void reset()
Reset the memory manager.
HeapMemoryManager & operator=(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(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.