Ion
|
This template class can be used in situations where you want to allocate an object that is not necessarily derived from Allocatable, but you still want to use an Allocator for the memory. More...
#include "scopedallocation.h"
Public Member Functions | |
ScopedAllocation (const AllocatorPtr &allocator) | |
This constructor allocates a single T instance using allocator, or the default allocator if a NULL pointer is passed. More... | |
ScopedAllocation (AllocationLifetime lifetime) | |
This constructor allocates a single T instance using the default allocator for lifetime. More... | |
ScopedAllocation (const AllocatorPtr &allocator, size_t count) | |
This constructor allocates count T instances using allocator, or the default allocator if a NULL pointer is passed. More... | |
ScopedAllocation (AllocationLifetime lifetime, size_t count) | |
This constructor allocates count T instances the default allocator for lifetime. More... | |
~ScopedAllocation () | |
The destructor deletes the instance(s) using the allocator. More... | |
T * | Get () const |
Returns a pointer to the allocated T instance(s). More... | |
DataContainerPtr | TransferToDataContainer (bool is_wipeable) |
Creates a DataContainer of the same type and transfers the data from the ScopedAllocation to it. More... | |
This template class can be used in situations where you want to allocate an object that is not necessarily derived from Allocatable, but you still want to use an Allocator for the memory.
Note that T must be default-constructable.
Examples: ///< Allocating a local variable: ScopedAllocation<Thing> s1(allocator); ///< Creates a Thing instance. DoSomethingWithAThing(s1.Get()); ///< Accesses the instance. ///< When s1 goes out of scope, the Thing is deleted using the Allocator.
///< Allocating a local POD array: ScopedAllocation<char> s2(allocator, 9); ///< Allocates an array of size 9. printf(s2.Get()); ///< Accesses the array. ///< When s2 goes out of scope, the array is deleted using the Allocator.
///< Transferring the contents of a ScopedAllocation to a DataContainer that ///< uses the same Allocator. (This can be useful for allocating an array of ///< objects with an Allocator for use in a DataContainer.): ScopedAllocation<int> s3(allocator, 9); ... ///< Fill in the data inside the array. DataContainerPtr dc = s3.TransferToDataContainer(true); ///< s3 is now empty; dc contains the data.
Definition at line 57 of file scopedallocation.h.
|
inlineexplicit |
This constructor allocates a single T instance using allocator, or the default allocator if a NULL pointer is passed.
Definition at line 61 of file scopedallocation.h.
|
inlineexplicit |
This constructor allocates a single T instance using the default allocator for lifetime.
Definition at line 67 of file scopedallocation.h.
References ion::base::AllocationManager::GetDefaultAllocatorForLifetime().
|
inline |
This constructor allocates count T instances using allocator, or the default allocator if a NULL pointer is passed.
Definition at line 73 of file scopedallocation.h.
|
inline |
This constructor allocates count T instances the default allocator for lifetime.
Definition at line 79 of file scopedallocation.h.
References ion::base::AllocationManager::GetDefaultAllocatorForLifetime().
|
inline |
The destructor deletes the instance(s) using the allocator.
Definition at line 84 of file scopedallocation.h.
References allocator_.
|
inline |
Returns a pointer to the allocated T instance(s).
This returns NULL if a count of 0 was passed to the constructor.
Definition at line 90 of file scopedallocation.h.
Referenced by ion::base::ZipAssetManager::RegisterAssetData().
|
inline |
Creates a DataContainer of the same type and transfers the data from the ScopedAllocation to it.
After this call, the ScopedAllocation will be empty, meaning that Get() will return a NULL pointer.
Definition at line 95 of file scopedallocation.h.
References allocator_.