CppCommon  1.0.4.1
C++ Common Library
allocator_null.inl
Go to the documentation of this file.
1 
9 namespace CppCommon {
10 
11 inline void* NullMemoryManager::malloc(size_t size, size_t alignment)
12 {
13  assert((size > 0) && "Allocated block size must be greater than zero!");
14  assert(Memory::IsValidAlignment(alignment) && "Alignment must be valid!");
15 
16  // Not enough memory...
17  return nullptr;
18 }
19 
20 inline void NullMemoryManager::free(void* ptr, size_t size)
21 {
22  assert((ptr != nullptr) && "Deallocated block must be valid!");
23 
24  if (ptr != nullptr)
25  {
26  // Update allocation statistics
27  _allocated -= size;
28  --_allocations;
29  }
30 }
31 
33 {
34  assert((_allocated == 0) && "Memory leak detected! Allocated memory size must be zero!");
35  assert((_allocations == 0) && "Memory leak detected! Count of active memory allocations must be zero!");
36 }
37 
38 } // namespace CppCommon
static bool IsValidAlignment(size_t alignment) noexcept
Is the given alignment valid?
Definition: memory.inl:13
void reset()
Reset the memory manager.
void free(void *ptr, size_t size)
Free the previously allocated memory block.
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