Ion
|
Allocatable is an abstract base class for classes whose memory is managed by an Allocator. More...
#include "allocatable.h"
Public Member Functions | |
virtual | ~Allocatable () |
The destructor clears the reference to the allocator. More... | |
const AllocatorPtr & | GetAllocator () const |
Returns the Allocator that was used for the instance. More... | |
const AllocatorPtr & | GetNonNullAllocator () const |
Return our allocator, or the default allocator if the instance was declared on the stack. More... | |
const AllocatorPtr & | GetAllocatorForLifetime (AllocationLifetime lifetime) const |
Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More... | |
void * | operator new (size_t size) |
The standard no-parameter new operator uses the default Allocator. More... | |
void * | operator new (size_t size, AllocationLifetime lifetime) |
This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More... | |
void * | operator new (size_t size, const AllocatorPtr &allocator) |
This overloaded version of the new operator takes the Allocator to use directly as a parameter. More... | |
void * | operator new (size_t size, const AllocatorPtr &allocator, void *ptr) |
Special operator new for using placement new with Allocatables. More... | |
void * | operator new (size_t size, void *ptr) |
The placement new operator is defined conventionally. More... | |
void | operator delete (void *ptr) |
Define the delete operator to use specialized functions dealing with an Allocator. More... | |
void | operator delete (void *ptr, AllocationLifetime lifetime) |
Windows requires these (or it issues C4291 warnings). More... | |
void | operator delete (void *ptr, const AllocatorPtr &allocator) |
void | operator delete (void *ptr, void *ptr2) |
The placement delete operator does nothing, as usual. More... | |
Protected Member Functions | |
Allocatable () | |
This constructor sets up the Allocator pointer. More... | |
Allocatable (const Allocatable &other) | |
The copy constructor works similarly to the default constructor. More... | |
void | operator= (const Allocatable &other) |
The assignment operator does nothing, since all members are intrinsically tied to a particular allocation. More... | |
Allocatable (const AllocatorPtr &allocator) | |
This constructor may only be used for Allocatables constructed on the stack; this is enforced via a DCHECK. More... | |
Friends | |
template<typename T > | |
class | StlAllocator |
Allow StlAllocator to set the placement Allocator. More... | |
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
This class defines new and delete operators that force the use of an Allocator to produce and reclaim the memory used by the instance. An Allocatable also makes an Allocator available via GetAllocator(). If the default constructor is used to construct the Allocatable, the returned Allocator is either the Allocator used to create the Allocatable or NULL if the Allocatable was created on the stack. If the stack-allocation-specific constructor taking an Allocator is used, then GetAllocator() returns that Allocator.
Allocatables may be copy-constructed or assigned. Note that the internal Allocator of the instance is not copied, however. This ensures that each Allocatable points to the Allocator that created it. Allocatables may also be created with placement new; if a particular Allocator is desired in the instance, use the special "new(allocator, memory_ptr)" version. Any Allocatable created with normal placement new ("new(memory_ptr) Type") will not contain an Allocator.
Allocatables may be used in STL or Alloc-STL containers (e.g., AllocVector). The rules for how the Allocator of a contained Allocatable is set are as follows: 1) Allocatables stored directly in the container as keys or values, or direct member variables of those, will return the container's Allocator when GetAllocator() is called on them. 2) Any Allocatable that is new'd uses whatever Allocator is provided to new as normal. For example, if a contained Allocatable creates another one with "new(an_allocator) AllocatableType" then that instance will have an_allocator as its Allocator. If no Allocator is passed to new then the default Allocator is used. This is consistent with non-contained Allocatable behavior.
Definition at line 60 of file allocatable.h.
|
virtual |
The destructor clears the reference to the allocator.
Definition at line 287 of file allocatable.cc.
References ion::base::SharedPtr< T >::Get().
|
protected |
This constructor sets up the Allocator pointer.
Allocatable class functions.
If this instance is created on the stack then GetAllocator() will return a NULL Allocator since the allocation and deallocation is performed by the compiler.
Definition at line 253 of file allocatable.cc.
|
protected |
The copy constructor works similarly to the default constructor.
It does not, however, copy any members from the other Allocatable, since these are intrinsically tied to a particular allocation.
Definition at line 257 of file allocatable.cc.
|
explicitprotected |
This constructor may only be used for Allocatables constructed on the stack; this is enforced via a DCHECK.
It allocates an Allocatable and stores the passed allocator to use in subsequent calls to GetAllocator(). This is useful when a derived class has members that need a non-NULL Allocator, for example to instantiate other Allocator-using objects.
Definition at line 274 of file allocatable.cc.
References DCHECK.
|
inline |
Returns the Allocator that was used for the instance.
This will be NULL if the instance was declared on the stack or created with normal placement new.
Definition at line 68 of file allocatable.h.
References allocator_.
Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().
|
inline |
Convenience function that returns the Allocator to use to allocate an object with a specific lifetime.
Definition at line 78 of file allocatable.h.
References ion::base::Allocator::GetAllocatorForLifetime().
Referenced by ion::text::BasicBuilder::BuildVertexData(), ion::text::OutlineBuilder::BuildVertexData(), ion::gfxutils::ShaderManager::CreateShaderProgram(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), ion::text::DynamicFontImage::FindImageDataIndex(), ion::gfx::Renderer::Renderer(), and ion::gfx::UpdateStateTable().
|
inline |
Return our allocator, or the default allocator if the instance was declared on the stack.
Definition at line 72 of file allocatable.h.
References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().
|
inline |
Define the delete operator to use specialized functions dealing with an Allocator.
Definition at line 109 of file allocatable.h.
|
inline |
Windows requires these (or it issues C4291 warnings).
Definition at line 112 of file allocatable.h.
|
inline |
Definition at line 113 of file allocatable.h.
|
inline |
The placement delete operator does nothing, as usual.
Definition at line 118 of file allocatable.h.
|
inline |
The standard no-parameter new operator uses the default Allocator.
Definition at line 84 of file allocatable.h.
|
inline |
This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.
Definition at line 88 of file allocatable.h.
|
inline |
This overloaded version of the new operator takes the Allocator to use directly as a parameter.
If the Allocator pointer is NULL, this uses the default Allocator.
Definition at line 95 of file allocatable.h.
|
inline |
Special operator new for using placement new with Allocatables.
Definition at line 100 of file allocatable.h.
|
inline |
The placement new operator is defined conventionally.
Definition at line 105 of file allocatable.h.
|
inlineprotected |
The assignment operator does nothing, since all members are intrinsically tied to a particular allocation.
Definition at line 133 of file allocatable.h.
|
friend |
Allow StlAllocator to set the placement Allocator.
Definition at line 144 of file allocatable.h.