MeVisLab Toolbox Reference
mlMemoryAllocator.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2008, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_MEMORY_ALLOCATOR_H
14 #define ML_MEMORY_ALLOCATOR_H
15 
16 #include <cstddef>
17 
18 #include "../mlMemoryManagerDllExport.h"
19 
22 typedef void* (*MLAllocationCallback)(size_t size);
23 
26 typedef void (*MLDeallocationCallback)(void* data);
27 
29 class MLMEMORYMANAGER_EXPORT MLMemoryAllocator
30 {
31 public:
36  static void initialize(MLAllocationCallback allocationCallback,
37  MLDeallocationCallback deallocationCallback);
38 
39 
41  static void* allocate(size_t size);
43  static void deallocate(void* data);
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 private:
47  MLMemoryAllocator() {};
48  ~MLMemoryAllocator() {};
50 
51 private:
52  static MLAllocationCallback _allocationCallback;
53  static MLDeallocationCallback _deallocationCallback;
54  static unsigned int _alreadyAllocatedMemory;
55 
56 #endif
57 };
58 
59 #endif // MLMEMORYALLOCATOR_H_INCLUDED
60 
The memory allocator used by the memory manager.
static void initialize(MLAllocationCallback allocationCallback, MLDeallocationCallback deallocationCallback)
Initializes the memory allocator.
static void deallocate(void *data)
Deallocate memory. Uses free if no deallocationCallback was specified.
static void * allocate(size_t size)
Allocate memory of the given size. Uses malloc if no allocationCallback was specified.
void(* MLDeallocationCallback)(void *data)
The callback function type for deallocating memory.
void *(* MLAllocationCallback)(size_t size)
The callback function type for allocating memory of a certain size.