StrArray array size and free space

Web Site  Methods

 
StrArray::SetSize
 
void SetSize (int newsize, int growby = -1)

SetSize will change the size of the array.  If the new size is greater than the current size, the necessary number of elements (initialized to an empty string) will be appended to the end of the array.  If the new size is smaller than the current size, the last few elements in the array will be deleted.

The passed growby value determines how to grow the array when elements are added to it.  The default of -1 means "automatically determine the growth factor" and is recommended for most cases. Passing any positive value in this parameter will cause the StrArray to grow by this number of "free element slots" when the array size should be increased and there is no more space in the internal array buffer.

 

 
StrArray::FreeExtra
 
void FreeExtra ()

FreeExtra is usually called when many elements were deleted from a StrArray object.  Calling this method will attempt to reduce the internal buffer of the array by removing free slots that appear when elements are deleted from the array.

With some implementations of the Standard Template Library (which is used internally by the class), this method may be a no-op. The only guaranteed way to remove unnecessary free space from the buffer of a StrArray is to create a new object, then copy all values from the old array into the new one by using Append.

 

 
StrArray::RemoveAll
 
void RemoveAll ()

RemoveAll  will delete all elements in the array and set its size to 0.

 

See alsoStrArray class