Ion: base/allocationmanager.h Source File

1 

18 #ifndef ION_BASE_ALLOCATIONMANAGER_H_

19 #define ION_BASE_ALLOCATIONMANAGER_H_

20 

21 #include "base/macros.h"

23 

24 namespace ion {

25 namespace base {

26 

30  public:

32 

36  GetInstance()->default_allocation_lifetime_ = lifetime;

37  }

39  return GetInstance()->default_allocation_lifetime_;

40  }

41 

59  mgr->default_allocators_[lifetime] =

60  allocator.Get() ? allocator : mgr->malloc_allocator_;

61  }

64  return GetInstance()->default_allocators_[lifetime];

65  }

66 

72  return mgr->default_allocators_[mgr->default_allocation_lifetime_];

73  }

74 

78  return GetInstance()->malloc_allocator_;

79  }

80 

86  return allocator.Get() ? allocator : GetDefaultAllocator();

87  }

88 

89  private:

92  class MallocAllocator;

93 

96 

99 

102 

104  AllocatorPtr default_allocators_[kNumAllocationLifetimes];

105 

108 

110 };

111 

112 }

113 }

114 

115 #endif // ION_BASE_ALLOCATIONMANAGER_H_

AllocationLifetime

All memory allocated within Ion uses an Allocator chosen based on the predicted lifetime of the targe...

AllocationManager is a singleton class that is used to manage Allocators used to allocate Ion objects...

static const AllocatorPtr & GetDefaultAllocator()

Convenience function that returns the default allocator to use when no lifetime is specified...

static const AllocatorPtr & GetNonNullAllocator(const AllocatorPtr &allocator)

This convenience function can be used where a non-NULL Allocator pointer is needed.

static void SetDefaultAllocatorForLifetime(AllocationLifetime lifetime, const AllocatorPtr &allocator)

Sets/returns the default Allocator to use for a specific AllocationLifetime.

static const AllocatorPtr & GetMallocAllocator()

Returns an allocator that performs conventional allocation and deallocation with malloc() and free()...

static AllocationLifetime GetDefaultAllocationLifetime()

static void SetDefaultAllocationLifetime(AllocationLifetime lifetime)

Sets/returns the AllocationLifetime that is assumed when a default new() operator is used for an Allo...

static const AllocatorPtr & GetDefaultAllocatorForLifetime(AllocationLifetime lifetime)