18 #ifndef ION_BASE_SCOPEDALLOCATION_H_
19 #define ION_BASE_SCOPEDALLOCATION_H_
23 #include "base/macros.h"
74 Init(allocator, count);
85 DeleteData(instance_ptr_, count_,
allocator_, memory_ptr_);
90 T*
Get()
const {
return instance_ptr_; }
96 return DataContainer::Create<T>(
105 void Init(
const AllocatorPtr& allocator,
size_t count) {
112 allocator_->AllocateMemory(
sizeof(
size_t) + count_ *
sizeof(
T));
113 instance_ptr_ =
new(memory_ptr_)
T[count_];
116 instance_ptr_ = NULL;
125 T* ptr = instance_ptr_;
126 instance_ptr_ = NULL;
132 static void Deleter(
void* data,
size_t count,
AllocatorPtr allocator,
134 DeleteData(reinterpret_cast<T*>(data), count, allocator, memory_ptr);
139 static void DeleteData(
T* data,
size_t count,
const AllocatorPtr& allocator,
143 for (
size_t i = 0; i < count; ++i)
147 allocator->DeallocateMemory(memory_ptr);
161 DISALLOW_COPY_AND_ASSIGN(ScopedAllocation);
167 #endif // ION_BASE_SCOPEDALLOCATION_H_
DataContainerPtr TransferToDataContainer(bool is_wipeable)
Creates a DataContainer of the same type and transfers the data from the ScopedAllocation to it...
T * Get() const
Returns a pointer to the allocated T instance(s).
AllocationLifetime
All memory allocated within Ion uses an Allocator chosen based on the predicted lifetime of the targe...
ScopedAllocation(AllocationLifetime lifetime)
This constructor allocates a single T instance using the default allocator for lifetime.
base::AllocatorPtr allocator_
The Allocator for the FreeTypeManager and all its Fonts.
ScopedAllocation(AllocationLifetime lifetime, size_t count)
This constructor allocates count T instances the default allocator for lifetime.
SharedPtr< Allocator > AllocatorPtr
static const AllocatorPtr & GetNonNullAllocator(const AllocatorPtr &allocator)
This convenience function can be used where a non-NULL Allocator pointer is needed.
~ScopedAllocation()
The destructor deletes the instance(s) using the allocator.
ScopedAllocation(const AllocatorPtr &allocator)
This constructor allocates a single T instance using allocator, or the default allocator if a NULL po...
This template class can be used in situations where you want to allocate an object that is not necess...
ScopedAllocation(const AllocatorPtr &allocator, size_t count)
This constructor allocates count T instances using allocator, or the default allocator if a NULL poin...
static const AllocatorPtr & GetDefaultAllocatorForLifetime(AllocationLifetime lifetime)