Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > Class Template Reference

Classes

class  const_iterator
 
class  iterator
 

Public Member Functions

 CFastArray ()
 
 CFastArray (const T *data, INDEXTYPE count)
 
 CFastArray (const CFastArray &src)
 
void SetGrowPolicy (GrowPolicy val)
 
GrowPolicy GetGrowPolicy ()
 
void SetMinCapacity (INDEXTYPE newCapacity)
 
void SetCapacity (INDEXTYPE newCapacity)
 
void SuspendShrink ()
 
void OnRecycle ()
 
void OnDrop ()
 
void SetCount (INDEXTYPE newVal)
 
void AddCount (INDEXTYPE addLength)
 
void resize (INDEXTYPE sz)
 for STL compatibility
 
INDEXTYPE GetCapacity () const
 
INDEXTYPE GetCount () const
 
INDEXTYPE size () const
 for STL compatibility
 
bool IsEmpty () const
 
void Clear ()
 
void ClearAndKeepCapacity ()
 
T_IN ElementAt (INDEXTYPE index) const
 
T & ElementAt (INDEXTYPE index)
 
T_IN operator[] (INDEXTYPE index) const
 
T & operator[] (INDEXTYPE index)
 
T * GetData ()
 
const T * GetData () const
 
void Add (T_IN value)
 
void push_back (T_IN value)
 
void Insert (INDEXTYPE indexAt, T_IN value)
 
void AddRange (const T *data, INDEXTYPE count)
 
void InsertRange (INDEXTYPE indexAt, const T *data, INDEXTYPE count)
 
void CopyRangeTo (CFastArray &dest, INDEXTYPE srcOffset, INDEXTYPE count) const
 
void CopyTo (CFastArray &dest) const
 
void CopyFrom (const CFastArray &src)
 
void CopyFrom (const T *from, INDEXTYPE fromCount)
 
void RemoveRange (INDEXTYPE index, INDEXTYPE count)
 
void RemoveAt (INDEXTYPE index)
 
bool RemoveOneByValue (T_IN value)
 
CFastArrayoperator= (const CFastArray &src)
 
INDEXTYPE FindByValue (T_IN value)
 
bool Contains (T_IN value)
 
bool Equals (const CFastArray &rhs) const
 
void clear ()
 for STL compatibility
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
iterator erase (iterator iter)
 
PopBack ()
 
void RemoveAndPullLast (INDEXTYPE index)
 
virtual void DataBlock_Free (void *data)
 
virtual void * DataBlock_Alloc (size_t length)
 
virtual void * DataBlock_Realloc (void *oldPtr, size_t newLength)
 

Static Public Attributes

static const size_t TYPE_SIZE = sizeof(T)
 

Protected Member Functions

void InitVars ()
 
virtual INDEXTYPE GetRecommendedCapacity (INDEXTYPE actualCount)
 
void BoundCheck (INDEXTYPE index) const
 

Protected Attributes

T * m_Data
 
INDEXTYPE m_Length
 
INDEXTYPE m_Capacity
 
INDEXTYPE m_minCapacity
 
bool m_suspendShrink
 
GrowPolicy m_growPolicy
 

Friends

class iterator
 
class const_iterator
 

Detailed Description

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
class Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >

Array class

Performance increase function for primitive type

  • The performance that manages array increases when RAWTYPE=true due to array factors are regarded as primitive type such as int. (In order to maximize the performance, sometimes memcpy can be used internally.)
  • However, only specific primitive types such as int, bool and byte can be used. It can be dangerous that the type with separate constructor, destructor and duplicator is used as array clause.

Major characteristics

  • Does not perform auto memory shrink in order to minimize heap access In other words, capacity never decreases. Therefore, if the circumstances must consider the side-effects of using too much memory then this object must not be used.
  • Internally, by using Fast heap, it is possible to decrease the load cuased by heap access. By default, this feature is off. But it can be changed by UseFastHeap.
  • Can use the metohd names of List<> of .Net framework, STL.vector and CAtlArray. And provides interator class that acts as STL.vector.iterator
Parameters
TClause type of array
T_IN_REFSet to true if you want the value to be passed by reference, or false for by value. Type of 8 or less of bytes such as int is passed faster if by value is selected.
RAWTYPETo check if the type is safe even if array element is processed as “raw memory copy”. int is safe but std.string is not safe. In case element type of array is not related to constructor, destructor and copy assignment operator, you can set it as “true”. If setting it as “true”, constructor, destructor and copy assignment will not be called for progression of construction, destruction and copy of array element that internally occurs when inserting & deleting & changing size. Therefore, processing speed will be improved. Default is “false”.
INDEXTYPEIt is strongly recommended to use the maximum size of array and one of index types like int32,int64 and intPtr. Casting load between int32 and int64 should be considered, so using the appropriate one is recommended. For example, packet size should be int32 because it does not exceed 2GB and if it is only for local process, intPtr is recommended. int64 is appropriate when int32 cannot deal with accurate value like network statistics.

Constructor & Destructor Documentation

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::CFastArray ( )
inline

Default constructor

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::CFastArray ( const T *  data,
INDEXTYPE  count 
)
inline

Constructor that copies external data

Parameters
srcThis is the pointer of the data array
countThis is the number of data in the array
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::CFastArray ( const CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > &  src)
inline

Constructor that copies external data

Parameters
srcCFastArray to be copied

Member Function Documentation

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::Add ( T_IN  value)
inline

Add at the end

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::AddRange ( const T *  data,
INDEXTYPE  count 
)
inline

Add a new array behind an array

Parameters
dataPointer of the array to be newly added.
countSize of the array to be added
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
iterator Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::begin ( )
inline

Acts similar as same name method of STL

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
const_iterator Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::begin ( ) const
inline

Acts similar as same name method of STL

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::Clear ( )
inline

Clean up array. Same as ClearAndKeepCapacity

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::ClearAndKeepCapacity ( )
inline

Clean up array. Same as Clear

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
bool Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::Contains ( T_IN  value)
inline

Returns true if value exists in the array.

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::CopyRangeTo ( CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > &  dest,
INDEXTYPE  srcOffset,
INDEXTYPE  count 
) const
inline

After adjusting the size of dest with count, part of all of src is copied to dest.

Parameters
destArray is copied to dest.
srcOffsetCopy the data after srcOffset within the array to dest.
countcount Copy arrays as the same number of count.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::CopyTo ( CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > &  dest) const
inline
Parameters
destcopy array to dest.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T_IN Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::ElementAt ( INDEXTYPE  index) const
inline

Array item that pointed by index

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T& Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::ElementAt ( INDEXTYPE  index)
inline

Array item that pointed by index

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
iterator Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::end ( )
inline

Acts similar as same name method of STL

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
const_iterator Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::end ( ) const
inline

Acts similar as same name method of STL

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
bool Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::Equals ( const CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > &  rhs) const
inline
  • Note: This is a simple memory comparison. This is crucial.
    Parameters
    rhsChecks if this contains same as rhs
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
iterator Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::erase ( iterator  iter)
inline

Acts similar as same name method of STL

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
INDEXTYPE Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::FindByValue ( T_IN  value)
inline
Parameters
valuecheck if there is an array that has the same value as “value”.
Returns
If there is the array that has the same value as “value”, the index is returned. If not found, -1 will be returned.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
INDEXTYPE Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::GetCapacity ( ) const
inline

Get the size of the capacity

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
INDEXTYPE Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::GetCount ( ) const
inline

Array size

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T* Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::GetData ( )
inline

Gets array buffer pointer

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
const T* Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::GetData ( ) const
inline

Gets array buffer pointer

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
GrowPolicy Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::GetGrowPolicy ( )
inline

Getting existing grow policy

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::Insert ( INDEXTYPE  indexAt,
T_IN  value 
)
inline

Move back item that pointed by indexAt then add value to place that pointed by indexAt

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::InsertRange ( INDEXTYPE  indexAt,
const T *  data,
INDEXTYPE  count 
)
inline

Add an array in the middle of an array. Push the area pointed at by indexAt behind and add it in the gap.

Parameters
indexAtIt is added after this index number.
datadata It is a pointer of the array to be inserted.
countSize of the array to be added.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
CFastArray& Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::operator= ( const CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE > &  src)
inline

Copy assignment operator

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T_IN Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::operator[] ( INDEXTYPE  index) const
inline

Array item that pointed by index

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T& Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::operator[] ( INDEXTYPE  index)
inline

Array item that pointed by index

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
T Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::PopBack ( )
inline

Remove the last information of the array within the array and return it.

template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::RemoveAndPullLast ( INDEXTYPE  index)
inline

After moving the last item to the place where index is pointing at and remove the last item. It is effective to use instead of Remove when you move the waist item from a collection where sequence is irrelevant.

Parameters
indexIndex to be removed.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::RemoveAt ( INDEXTYPE  index)
inline
Parameters
indexRemove index th item
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
bool Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::RemoveOneByValue ( T_IN  value)
inline
Parameters
valueSeek same value as value from the first then remove it
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::RemoveRange ( INDEXTYPE  index,
INDEXTYPE  count 
)
inline

Remove as many as the count from the (index)th item.

Parameters
indexIndex of the array to be removed.
countRemove as many as the number of count from the index.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::SetCapacity ( INDEXTYPE  newCapacity)
inline

Balances the buffer(capacity) possessed by array

  • Capacity is only increased, not decreased.
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::SetCount ( INDEXTYPE  newVal)
inline

Adjust the array size

  • When adjusting the array size, the capacity increases sufficiently.
    Parameters
    newValSize of the new array
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::SetGrowPolicy ( GrowPolicy  val)
inline

Set the weighted value type when the array size of this object increases. For details, refer to GrowPolicy.

Parameters
valThe type to the weighted value of the array
template<typename T, bool T_IN_REF = true, bool RAWTYPE = false, typename INDEXTYPE = intptr_t>
void Proud::CFastArray< T, T_IN_REF, RAWTYPE, INDEXTYPE >::SetMinCapacity ( INDEXTYPE  newCapacity)
inline

Set the minimum buffer size. When the buffer (capacity) size increases, set it at least bigger than this size.

Parameters
newCapacityMinimum capacity size