Allocator.
More...
#include <base/mem/Allocator.h>
Inherited by ReferenceCountedAllocator< TYPE >.
|
static void | initialize (TYPE *dest, const TYPE *end) |
|
static void | initialize (TYPE *dest, const TYPE *end, const TYPE &value) |
|
static void | initializeByCopy (TYPE *restrict dest, const TYPE *restrict src, MemorySize count) |
|
static void | destroy (TYPE *begin, const TYPE *_end, MemorySize &destroyedCount) |
|
static void | destroy2 (TYPE *begin, const TYPE *end) |
|
static void | initializeByMove (TYPE *dest, TYPE *src, const TYPE *end) |
|
static void | initializeByMove (TYPE *dest, TYPE *src, const TYPE *end, bool &moved) |
|
static MemorySize | align (MemorySize offset) noexcept |
|
|
static constexpr bool | useSafeDestroy = false |
|
|
enum | MemoryFill { INIT_MEMORY = 0xaa,
DESTROY_OBJECT = 0xbb,
RELEASE_MEMORY = 0xdd
} |
|
|
Span< TYPE > | detach () |
|
void | attach (TYPE *_buffer, MemorySize _size) |
|
void | attach (const Span< TYPE > &span) |
|
MemorySize | getAdjustedSize (MemorySize size) const noexcept |
|
TYPE * | allocate (const MemorySize size) |
|
TYPE * | resize (TYPE *buffer, const MemorySize newSize, const MemorySize originalSize) |
|
bool | canResizeInplace () const noexcept |
|
TYPE * | tryResize (TYPE *buffer, const MemorySize newSize, const MemorySize originalSize) noexcept |
|
void | release (TYPE *buffer, const MemorySize size) |
|
|
static void | fill (TYPE *dest, MemorySize size, MemoryFill memoryFill) |
|
template<class TYPE>
class Allocator< TYPE >
Allocator.
Allocator of resizeable memory block. The implementation is not MT-safe.
Use capacity to avoid default construction.
- See also
- ReferenceCountedAllocator
- Version
- 1.2
◆ Allocator() [1/3]
Initializes an empty allocator.
◆ Allocator() [2/3]
Initializes an allocator of the specified size without initializing the elements. Raises MemoryException if unable to allocate enough memory to hold the requested number of elements.
- Parameters
-
size | Specifies the initial size of the allocator. |
◆ Allocator() [3/3]
Initializes allocator from other allocator.
◆ allocate()
template<class TYPE >
TYPE* Allocator< TYPE >::allocate |
( |
const MemorySize |
size | ) |
|
|
inlineprotected |
◆ attach() [1/2]
◆ attach() [2/2]
template<class TYPE >
void Allocator< TYPE >::attach |
( |
TYPE * |
_buffer, |
|
|
MemorySize |
_size |
|
) |
| |
|
inlineprotected |
◆ begin() [1/2]
Returns the first element of the allocator as a non-modifying iterator.
◆ begin() [2/2]
Returns the first element of the allocator as a modifying iterator.
◆ canResizeInplace()
template<class TYPE >
bool Allocator< TYPE >::canResizeInplace |
( |
| ) |
const |
|
inlineprotectednoexcept |
Inplace memory resize supported.
◆ clear()
Clear buffer. Capacity is ignored.
◆ destroy()
template<class TYPE >
static void Allocator< TYPE >::destroy |
( |
TYPE * |
begin, |
|
|
const TYPE * |
_end, |
|
|
MemorySize & |
destroyedCount |
|
) |
| |
|
inlinestatic |
Destroys the elements of the sequence. Does nothing for uninitializeable objects.
◆ detach()
◆ end() [1/2]
Returns the end of the allocator as a non-modifying iterator.
◆ end() [2/2]
Returns the end of the allocator as a modifying iterator.
◆ ensureCapacity() [1/2]
Sets the capacity to the current size. Only heap will be allocated so objects won't be initialized. Required when object do not have default initialization.
◆ ensureCapacity() [2/2]
template<class TYPE >
void Allocator< TYPE >::ensureCapacity |
( |
MemorySize |
_capacity | ) |
|
|
inlinenoexcept |
Sets the capacity. Only heap will be allocated so objects won't be initialized. Required when object do not have default initialization.
◆ fill()
template<class TYPE >
static void Allocator< TYPE >::fill |
( |
TYPE * |
dest, |
|
|
MemorySize |
size, |
|
|
MemoryFill |
memoryFill |
|
) |
| |
|
inlinestaticprotected |
Fills the memory with the given marker.
◆ garbageCollect()
template<class TYPE >
MemoryDiff Allocator< TYPE >::garbageCollect |
( |
| ) |
|
|
inline |
Releases unused memory. Requested capacity is ignored. Any object must not have a cached pointer/iterator to the elements!
- Returns
- Returns the bytes released.
◆ getAdjustedSize()
template<class TYPE >
MemorySize Allocator< TYPE >::getAdjustedSize |
( |
MemorySize |
size | ) |
const |
|
inlineprotectednoexcept |
Returns the actual size to allocate. Ie. compensated for capacity.
◆ getBeginIterator()
Returns the first element of the allocator as a modifying iterator.
◆ getBeginReadIterator()
Returns the first element of the allocator as a non-modifying iterator.
◆ getByteSize()
template<class TYPE >
MemorySize Allocator< TYPE >::getByteSize |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of allocated bytes.
◆ getCapacity()
template<class TYPE >
MemorySize Allocator< TYPE >::getCapacity |
( |
| ) |
const |
|
inlinenoexcept |
◆ getElements() [1/2]
template<class TYPE >
const TYPE* Allocator< TYPE >::getElements |
( |
| ) |
const |
|
inlinenoexcept |
Returns the elements of the allocator for non-modifying access.
◆ getElements() [2/2]
Returns the elements of the allocator for modifying access.
◆ getEndIterator()
Returns the end of the allocator as a modifying iterator.
◆ getEndReadIterator()
Returns the end of the allocator as a non-modifying iterator.
◆ getEnumerator()
Returns a modifying enumerator of the allocator.
◆ getGarbageByteSize()
template<class TYPE >
MemorySize Allocator< TYPE >::getGarbageByteSize |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of bytes that could be garbage collected.
◆ getReadEnumerator()
Returns a non-modifying enumerator of the allocator.
◆ getSize()
template<class TYPE >
MemorySize Allocator< TYPE >::getSize |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of elements of the allocator.
◆ initialize() [1/2]
template<class TYPE >
static void Allocator< TYPE >::initialize |
( |
TYPE * |
dest, |
|
|
const TYPE * |
end |
|
) |
| |
|
inlinestatic |
Initializes the elements of the sequence using the default constructor. Uninitializeable objects are not initialized.
◆ initialize() [2/2]
template<class TYPE >
static void Allocator< TYPE >::initialize |
( |
TYPE * |
dest, |
|
|
const TYPE * |
end, |
|
|
const TYPE & |
value |
|
) |
| |
|
inlinestatic |
Initializes the elements of the sequence using the given value. Uninitializeable objects are not initialized.
◆ initializeByCopy()
template<class TYPE >
static void Allocator< TYPE >::initializeByCopy |
( |
TYPE *restrict |
dest, |
|
|
const TYPE *restrict |
src, |
|
|
MemorySize |
count |
|
) |
| |
|
inlinestatic |
Initializes the elements of the sequence by copying elements from other sequence. The memory image is copied directly for relocatable objects.
◆ initializeByMove() [1/2]
template<class TYPE >
static void Allocator< TYPE >::initializeByMove |
( |
TYPE * |
dest, |
|
|
TYPE * |
src, |
|
|
const TYPE * |
end |
|
) |
| |
|
inlinestatic |
Initializes the elements of the sequence by moving elements from other sequence. Arrays must not overlap.
◆ initializeByMove() [2/2]
template<class TYPE >
static void Allocator< TYPE >::initializeByMove |
( |
TYPE * |
dest, |
|
|
TYPE * |
src, |
|
|
const TYPE * |
end, |
|
|
bool & |
moved |
|
) |
| |
|
inlinestatic |
Initializes the elements of the sequence by moving elements from other sequence. Arrays must not overlap.
◆ isEmpty()
Returns true if no elements are allocated.
◆ operator=()
Assignment of allocator by allocator.
◆ release()
template<class TYPE >
void Allocator< TYPE >::release |
( |
TYPE * |
buffer, |
|
|
const MemorySize |
size |
|
) |
| |
|
inlineprotected |
◆ resize()
template<class TYPE >
TYPE* Allocator< TYPE >::resize |
( |
TYPE * |
buffer, |
|
|
const MemorySize |
newSize, |
|
|
const MemorySize |
originalSize |
|
) |
| |
|
inlineprotected |
◆ setSize() [1/2]
template<class TYPE >
void Allocator< TYPE >::setSize |
( |
MemorySize |
size | ) |
|
|
inline |
Sets the number of elements of the allocator. If the size is increased the original elements are not modified and the newly allocated elements are not initialized. Raises MemoryException if unable to allocate additional memory (does not throw an exception when the size is decreased or unchanged). If the size is reduced the elements up to the new size are unchanged.
- Parameters
-
◆ setSize() [2/2]
template<class TYPE >
void Allocator< TYPE >::setSize |
( |
MemorySize |
size, |
|
|
const TYPE & |
value |
|
) |
| |
|
inline |
Same as setSize() but fills new elements with the given value instead of using default initialization.
◆ setSizeImpl()
template<class TYPE >
void Allocator< TYPE >::setSizeImpl |
( |
MemorySize |
size, |
|
|
const TYPE * |
value |
|
) |
| |
|
inline |
Sets the number of elements of the allocator. If the size is increased the original elements are not modified and the newly allocated elements are not initialized. Raises MemoryException if unable to allocate additional memory (does not throw an exception when the size is decreased or unchanged). If the size is reduced the elements up to the new size are unchanged.
- Parameters
-
◆ tryResize()
template<class TYPE >
TYPE* Allocator< TYPE >::tryResize |
( |
TYPE * |
buffer, |
|
|
const MemorySize |
newSize, |
|
|
const MemorySize |
originalSize |
|
) |
| |
|
inlineprotectednoexcept |
Try to inplace resize buffer.