Ion
|
Allocator is an abstract base class for a memory allocator used for Ion objects derived from Allocatable. More...
#include "allocator.h"
Public Member Functions | |
void * | AllocateMemory (size_t size) |
Allocates memory of the given size. More... | |
void | DeallocateMemory (void *p) |
Deallocates a previously-allocated memory block. More... | |
virtual const AllocatorPtr & | GetAllocatorForLifetime (AllocationLifetime lifetime) const |
Returns the correct Allocator to use to allocate memory with a specific lifetime. More... | |
void | SetTracker (const AllocationTrackerPtr &tracker) |
Sets/returns an AllocationTracker instance used to track the workings of this instance. More... | |
const AllocationTrackerPtr & | GetTracker () const |
int | GetRefCount () const |
GetRefCount() is part of the interface necessary for SharedPtr. More... | |
Protected Member Functions | |
Allocator () | |
~Allocator () override | |
The destructor is protected because all instances should be managed through SharedPtr. More... | |
virtual void * | Allocate (size_t size)=0 |
Derived classes must define this to allocate size bytes of memory and return a pointer to it. More... | |
virtual void | Deallocate (void *p)=0 |
Derived classes must define this to return memory previously allocated by a call to Allocate(). More... | |
Allocator is an abstract base class for a memory allocator used for Ion objects derived from Allocatable.
The lifetime of an Allocator is managed through AllocatorPtr instances (SharedPtr to an Allocator). Every Allocatable created with an Allocator maintains an AllocatorPtr to that Allocator. Therefore, clients should maintain at least one other AllocatorPtr to an Allocator to prevent it from being destroyed while it is still needed.
Definition at line 61 of file allocator.h.
|
inlineprotected |
Definition at line 85 of file allocator.h.
|
overrideprotected |
The destructor is protected because all instances should be managed through SharedPtr.
Definition at line 25 of file allocator.cc.
|
protectedpure virtual |
Derived classes must define this to allocate size bytes of memory and return a pointer to it.
The returned memory must make the same alignment guarantee that malloc() makes: the memory is suitably aligned for any kind of variable.
Referenced by AllocateMemory().
void * ion::base::Allocator::AllocateMemory | ( | size_t | size | ) |
Allocates memory of the given size.
Definition at line 32 of file allocator.cc.
References Allocate(), and ion::base::SharedPtr< T >::Get().
Referenced by ion::base::StlAllocator< T >::allocate(), ion::image::NinePatch::BuildImage(), ion::base::DataContainer::CreateAndCopy(), ion::base::internal_variant_utils::ManualConstructor< T15 >::Init(), and ion::base::internal_variant_utils::ManualConstructor< T15 >::InitArray().
|
protectedpure virtual |
Derived classes must define this to return memory previously allocated by a call to Allocate().
Referenced by DeallocateMemory().
void ion::base::Allocator::DeallocateMemory | ( | void * | p | ) |
Deallocates a previously-allocated memory block.
Definition at line 39 of file allocator.cc.
References Deallocate(), and ion::base::SharedPtr< T >::Get().
Referenced by ion::base::DataContainer::AllocatorDeleter(), ion::base::StlAllocator< T >::deallocate(), and ion::base::internal_variant_utils::ManualConstructor< T15 >::Destroy().
|
virtual |
Returns the correct Allocator to use to allocate memory with a specific lifetime.
The base class implements this to return the default Allocator for the lifetime from the AllocationManager. Derived classes may override this to provide a different Allocator to support different allocation schemes.
Definition at line 27 of file allocator.cc.
References ion::base::AllocationManager::GetDefaultAllocatorForLifetime().
Referenced by ion::text::Builder::Build(), ion::base::DataContainer::CreateAndCopy(), and ion::base::Allocatable::GetAllocatorForLifetime().
|
inlineinherited |
GetRefCount() is part of the interface necessary for SharedPtr.
Definition at line 34 of file shareable.h.
Referenced by ion::base::Notifier::RemoveReceiver().
|
inline |
Definition at line 82 of file allocator.h.
|
inline |
Sets/returns an AllocationTracker instance used to track the workings of this instance.
The pointer is NULL by default, resulting in no tracking. Note that it is probably a bad idea to change the tracker instance while any memory allocated by this instance is still active.
Definition at line 81 of file allocator.h.