Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocationmanager.cc
Go to the documentation of this file.
1 
19 
20 #include <cstdlib> // For malloc() and free()
21 
23 
24 namespace ion {
25 namespace base {
26 
28 
33 
34 
35 class AllocationManager::MallocAllocator : public Allocator {
36  public:
37  void* Allocate(size_t size) override { return malloc(size); }
38  void Deallocate(void* p) override { free(p); }
39 };
40 
42 
47 
48 
49 AllocationManager::AllocationManager()
50  : default_allocation_lifetime_(kMediumTerm),
51  malloc_allocator_(new MallocAllocator) {
53  default_allocators_[kShortTerm] =
54  default_allocators_[kMediumTerm] =
55  default_allocators_[kLongTerm] = malloc_allocator_;
56 }
57 
59 }
60 
61 AllocationManager* AllocationManager::GetInstance() {
63  return manager;
64 }
65 
66 } // namespace base
67 } // namespace ion
kShortTerm is used for objects that are very transient in nature, such as scratch memory used to comp...
Definition: allocator.h:36
#define ION_DECLARE_SAFE_STATIC_POINTER(type, variable)
Declare a static non-array pointer and calls a default constructor.
AllocationManager is a singleton class that is used to manage Allocators used to allocate Ion objects...
kLongTerm is used for objects that have persistent lifetimes, such as managers.
Definition: allocator.h:44
kMediumTerm is used for objects that don't fall into the kShortTerm or kLongTerm categories.
Definition: allocator.h:40