Nebula
Loading...
Searching...
No Matches
Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES > Class Template Reference

#include <arrayallocatorsafe.h>

Detailed Description

template<uint MAX_ALLOCS = 0xFFFF, class ... TYPES>
class Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >

The ArrayAllocatorSafe provides a thread safe variadic list of types which is to be contained in the allocator and fetching each value by providing the index into the list of types, which means the members are nameless.

Note that this is not a container for multiple arrays, but a object allocator that uses multiple arrays to store their variables parallelly, and should be treated as such.

There are two versions of this type, an unsafe and a safe one. Both are implemented in the same way.

The thread safe allocator requires the Get-methods to be within an Enter/Leave lockstep phase.

See also
arrayallocator.h

Public Member Functions

 ArrayAllocatorSafe ()
 constructor
 
 ArrayAllocatorSafe (ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > &&rhs)
 move constructor
 
 ArrayAllocatorSafe (const ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > &rhs)
 copy constructor
 
 ~ArrayAllocatorSafe ()
 destructor
 
void operator= (const ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > &rhs)
 assign operator
 
void operator= (ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > &&rhs)
 move operator
 
uint32_t Alloc ()
 allocate a new resource
 
void EraseIndex (const uint32_t id)
 Erase element for each.
 
void EraseIndexSwap (const uint32_t id)
 Erase element for each.
 
template<int MEMBER>
tuple_array_t< MEMBER, TYPES... > & Get (const uint32_t index)
 get single item from resource
 
template<int MEMBER>
const tuple_array_t< MEMBER, TYPES... > & ConstGet (const uint32_t index) const
 Get const explicitly.
 
template<int MEMBER>
const tuple_array_t< MEMBER, TYPES... > & Get (const uint32_t index) const
 same as 32 bit get, but const
 
template<int MEMBER>
void Set (const uint32_t index, const tuple_array_t< MEMBER, TYPES... > &type)
 set single item
 
template<int MEMBER>
const Util::Array< tuple_array_t< MEMBER, TYPES... > > & GetArray () const
 get array const reference
 
template<int MEMBER>
Util::Array< tuple_array_t< MEMBER, TYPES... > > & GetArray ()
 get array
 
void Set (const uint32_t index, TYPES...)
 set for each in tuple
 
const uint32_t Size () const
 get number of used indices
 
void Reserve (uint32_t size)
 grow capacity of arrays to size
 
void Clear ()
 clear entire allocator and start from scratch.
 
void UpdateSize ()
 Any reserve and direct array access might mess with the size.
 
void TryAcquire (const uint32_t index)
 Spinlock to acquire.
 
bool Acquire (const uint32_t index)
 Acquire element, asserts if false and returns true if this call acquired.
 
void Release (const uint32_t index)
 Release an object, the next thread that acquires may use this instance as it fits.
 

Protected Attributes

uint32_t size
 
std::tuple< Util::PinnedArray< MAX_ALLOCS, TYPES >... > objects
 
Util::PinnedArray< MAX_ALLOCS, Threading::ThreadIdowners
 
Threading::Spinlock allocationLock
 

Constructor & Destructor Documentation

◆ ArrayAllocatorSafe() [1/3]

template<uint MAX_ALLOCS, class ... TYPES>
Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::ArrayAllocatorSafe ( )
inline

constructor

◆ ArrayAllocatorSafe() [2/3]

template<uint MAX_ALLOCS, class ... TYPES>
Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::ArrayAllocatorSafe ( ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > && rhs)
inline

move constructor

◆ ArrayAllocatorSafe() [3/3]

template<uint MAX_ALLOCS, class ... TYPES>
Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::ArrayAllocatorSafe ( const ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > & rhs)
inline

copy constructor

◆ ~ArrayAllocatorSafe()

template<uint MAX_ALLOCS, class ... TYPES>
Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::~ArrayAllocatorSafe ( )
inline

destructor

Member Function Documentation

◆ Acquire()

template<uint MAX_ALLOCS, class ... TYPES>
bool Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Acquire ( const uint32_t index)

Acquire element, asserts if false and returns true if this call acquired.

◆ Alloc()

template<uint MAX_ALLOCS, class ... TYPES>
uint32_t Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Alloc ( )
inline

allocate a new resource

Allocs an object AND acquires it.

◆ Clear()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Clear ( )
inline

clear entire allocator and start from scratch.

◆ ConstGet()

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
const tuple_array_t< MEMBER, TYPES... > & Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::ConstGet ( const uint32_t index) const
inline

Get const explicitly.

◆ EraseIndex()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::EraseIndex ( const uint32_t id)
inline

Erase element for each.

◆ EraseIndexSwap()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::EraseIndexSwap ( const uint32_t id)
inline

Erase element for each.

◆ Get() [1/2]

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
tuple_array_t< MEMBER, TYPES... > & Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Get ( const uint32_t index)
inline

get single item from resource

◆ Get() [2/2]

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
const tuple_array_t< MEMBER, TYPES... > & Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Get ( const uint32_t index) const
inline

same as 32 bit get, but const

◆ GetArray() [1/2]

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
Util::Array< tuple_array_t< MEMBER, TYPES... > > & Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::GetArray ( )
inline

get array

◆ GetArray() [2/2]

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
const Util::Array< tuple_array_t< MEMBER, TYPES... > > & Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::GetArray ( ) const
inline

get array const reference

◆ operator=() [1/2]

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::operator= ( ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > && rhs)
inline

move operator

◆ operator=() [2/2]

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::operator= ( const ArrayAllocatorSafe< MAX_ALLOCS, TYPES... > & rhs)
inline

assign operator

◆ Release()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Release ( const uint32_t index)

Release an object, the next thread that acquires may use this instance as it fits.

◆ Reserve()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Reserve ( uint32_t size)
inline

grow capacity of arrays to size

◆ Set() [1/2]

template<uint MAX_ALLOCS, class ... TYPES>
template<int MEMBER>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Set ( const uint32_t index,
const tuple_array_t< MEMBER, TYPES... > & type )
inline

set single item

◆ Set() [2/2]

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Set ( const uint32_t index,
TYPES... values )

set for each in tuple

◆ Size()

template<uint MAX_ALLOCS, class ... TYPES>
const uint32_t Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::Size ( ) const
inline

get number of used indices

◆ TryAcquire()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::TryAcquire ( const uint32_t index)

Spinlock to acquire.

◆ UpdateSize()

template<uint MAX_ALLOCS, class ... TYPES>
void Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::UpdateSize ( )

Any reserve and direct array access might mess with the size.

This will update the size to reflect the first member array size in objects.

Member Data Documentation

◆ allocationLock

template<uint MAX_ALLOCS = 0xFFFF, class ... TYPES>
Threading::Spinlock Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::allocationLock
protected

◆ objects

template<uint MAX_ALLOCS = 0xFFFF, class ... TYPES>
std::tuple<Util::PinnedArray<MAX_ALLOCS, TYPES>...> Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::objects
protected

◆ owners

template<uint MAX_ALLOCS = 0xFFFF, class ... TYPES>
Util::PinnedArray<MAX_ALLOCS, Threading::ThreadId> Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::owners
protected

◆ size

template<uint MAX_ALLOCS = 0xFFFF, class ... TYPES>
uint32_t Util::ArrayAllocatorSafe< MAX_ALLOCS, TYPES >::size
protected

The documentation for this class was generated from the following file: