Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocator.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_ALLOCATOR_H_
19 #define ION_BASE_ALLOCATOR_H_
20 
21 #include "base/macros.h"
23 #include "ion/base/logging.h"
24 #include "ion/base/shareable.h"
25 #include "ion/base/sharedptr.h"
26 
27 namespace ion {
28 namespace base {
29 
37 
41 
45 };
46 
48 static const int kNumAllocationLifetimes = kLongTerm + 1;
49 
51 class Allocator;
53 
61 class ION_API Allocator : public Shareable {
62  public:
64  void* AllocateMemory(size_t size);
65 
67  void DeallocateMemory(void* p);
68 
74  virtual const AllocatorPtr& GetAllocatorForLifetime(
75  AllocationLifetime lifetime) const;
76 
81  void SetTracker(const AllocationTrackerPtr& tracker) { tracker_ = tracker; }
82  const AllocationTrackerPtr& GetTracker() const { return tracker_; }
83 
84  protected:
85  Allocator() {}
86 
89  ~Allocator() override;
90 
95  virtual void* Allocate(size_t size) = 0;
96 
99  virtual void Deallocate(void* p) = 0;
100 
101  private:
102  AllocationTrackerPtr tracker_;
103 
104  DISALLOW_COPY_AND_ASSIGN(Allocator);
105 };
106 
107 } // namespace base
108 } // namespace ion
109 
110 #endif // ION_BASE_ALLOCATOR_H_
kShortTerm is used for objects that are very transient in nature, such as scratch memory used to comp...
Definition: allocator.h:36
const AllocationTrackerPtr & GetTracker() const
Definition: allocator.h:82
AllocationLifetime
All memory allocated within Ion uses an Allocator chosen based on the predicted lifetime of the targe...
Definition: allocator.h:33
SharedPtr< Allocator > AllocatorPtr
Definition: allocator.h:51
void SetTracker(const AllocationTrackerPtr &tracker)
Sets/returns an AllocationTracker instance used to track the workings of this instance.
Definition: allocator.h:81
Shareable is an abstract base class for any object that can be shared via the SharedPtr class...
Definition: shareable.h:31
Allocator is an abstract base class for a memory allocator used for Ion objects derived from Allocata...
Definition: allocator.h:61
Copyright 2016 Google Inc.
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