#include <BasicArray.h>
Public Member Functions | |
| BasicArray (unsigned int initialCapacity=0) | |
| ~BasicArray () | |
| bool | isEmpty () const |
| unsigned int | getSize () const |
| unsigned int | getCapacity () const |
| void | clear () |
| unsigned int | put (const T &x) |
| T & | get (const unsigned int i) |
| BasicArray< T > & | operator= (const BasicArray< T > &rhs) |
WARNING class constructors and destructors are not called. Allocated memory is initially set to zero. This works well with arrays of pointers or basic data types, but will not work for classes such as std::string which requires the constructor be called.
Definition at line 44 of file BasicArray.h.
| BasicArray< T >::BasicArray | ( | unsigned int | initialCapacity = 0 |
) | [inline] |
Create an empty array.
| initialCapacity | Initially allocate this many spaces. |
Definition at line 64 of file BasicArray.h.
| BasicArray< T >::~BasicArray | ( | ) | [inline] |
Destruct the array and all the data in it.
Definition at line 77 of file BasicArray.h.
| bool BasicArray< T >::isEmpty | ( | ) | const [inline] |
| unsigned int BasicArray< T >::getSize | ( | ) | const [inline] |
Definition at line 88 of file BasicArray.h.
Referenced by BasicDynamicClassFactory::create(), BasicClassGroupFactory::create(), CC3DTransaction::createPreasureFields(), BasicDynamicClassFactory::getNumNodes(), BasicClassGroupArray::getSize(), and BasicClassGroupFactory::~BasicClassGroupFactory().
| unsigned int BasicArray< T >::getCapacity | ( | ) | const [inline] |
setSize() will increase the array capacity if the new size is larger than the current capacity.
| size | The new array size. Will always be >= to getSize(). |
Definition at line 110 of file BasicArray.h.
| void BasicArray< T >::clear | ( | ) | [inline] |
Modifying or deallocating this buffer may adversely effect the contents of the array.
A pointer to the internal buffer. Set size to zero and deallocate memory.
| initialCapacity | New capacity. Set size to zero. Does not effect capacity. Memory is not initialized to zero! |
Definition at line 161 of file BasicArray.h.
| unsigned int BasicArray< T >::put | ( | const T & | x | ) | [inline] |
Increase array capacity if minCapacity is greater than the current capacity. The capacity will be increased to the larger of minCapacity or multiple times the current capacity. The default value for multiple is 2.0. The advantage of this liberal memory allocation comes from the unfortunate side effect that when a memory block is reallocated it may be copied to a new location. Doubling the capacity reduces the amortized time complexity of adding n elements one at a time from O(n^2) to O(n*log(n)). The disadvantage is that up to twice as much memory may be used. If you know the maximum size of the array ahead of time you can set the capacity to that size in the constructor. You may also pass a multiple of zero causing increase to allocate no more than minCapacity.
If memory allocation fails when capacity is greater than minCapacity then allocation is retried with capacity equal to minCapacity. If allocation fails again an std::bad_alloc() exception will be thrown.
| minCapacity | The minimum number of array slots needed. | |
| multiple | The minimum capacity multiplier. Calling this function assures that the array capacity is equal to its size by releasing any extra allocated memory. shrink() should normally only be used after the last put() call and before a call to adopt(). However, when the difference between capacity and size is small the recovered memory will often not be usable because of memory fragmentation. As a rule of thumb do not bother with shrink() when array sizes are small or when you have only a few array instances. It is generally more efficient to set the array capacity in the constructor. |
| x | A reference to the new array element |
Definition at line 234 of file BasicArray.h.
Referenced by BasicClassGroupArray::create(), BasicClassGroupFactory::registerClass(), and BasicDynamicClassFactory::registerNode().
| T& BasicArray< T >::get | ( | const unsigned int | i | ) | [inline] |
Add an array element. If there is all ready an element at this index it will be overwritten. If the index is beyond the current size of the array the array size will be automatically increased.
| i | The index of the array element. | |
| x | The new array element. Add an array of elements to the end of the array. | |
| x | A pointer to the elements to be added. | |
| count | The number of elements to be added. |
| i | The starting index. | |
| x | A pointer to the elements to be added. | |
| count | The number of elements to copy into the array. Allocate space for | |
| count | elements at the end of the array. |
| count | elements at position | |
| i. | This space may all ready be occupied by other array elements and writing to this memory may destroy their contents. If | |
| i | + | |
| count | is geater than the array size then the array size will be increased. You should normally use the put and get methods to access the array contents. |
| i | The index of the array element. |
Definition at line 322 of file BasicArray.h.
| BasicArray<T>& BasicArray< T >::operator= | ( | const BasicArray< T > & | rhs | ) | [inline] |
Definition at line 329 of file BasicArray.h.
1.5.6