Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocator.cc
Go to the documentation of this file.
1 
18 #include "ion/base/allocator.h"
19 
21 
22 namespace ion {
23 namespace base {
24 
26 
28  AllocationLifetime lifetime) const {
30 }
31 
32 void* Allocator::AllocateMemory(size_t size) {
33  void* ptr = Allocate(size);
34  if (AllocationTracker* tracker = tracker_.Get())
35  tracker->TrackAllocation(*this, size, ptr);
36  return ptr;
37 }
38 
40  if (AllocationTracker* tracker = tracker_.Get())
41  tracker->TrackDeallocation(*this, p);
42  Deallocate(p);
43 }
44 
45 } // namespace base
46 } // namespace ion
AllocationTracker is an abstract base class for objects that track memory.
~Allocator() override
The destructor is protected because all instances should be managed through SharedPtr.
Definition: allocator.cc:25
AllocationLifetime
All memory allocated within Ion uses an Allocator chosen based on the predicted lifetime of the targe...
Definition: allocator.h:33
virtual const AllocatorPtr & GetAllocatorForLifetime(AllocationLifetime lifetime) const
Returns the correct Allocator to use to allocate memory with a specific lifetime. ...
Definition: allocator.cc:27
virtual void Deallocate(void *p)=0
Derived classes must define this to return memory previously allocated by a call to Allocate()...
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
Definition: sharedptr.h:89
void DeallocateMemory(void *p)
Deallocates a previously-allocated memory block.
Definition: allocator.cc:39
void * AllocateMemory(size_t size)
Allocates memory of the given size.
Definition: allocator.cc:32
virtual void * Allocate(size_t size)=0
Derived classes must define this to allocate size bytes of memory and return a pointer to it...
static const AllocatorPtr & GetDefaultAllocatorForLifetime(AllocationLifetime lifetime)