Dynamic arrays

From ZDoom Wiki
Jump to: navigation, search
Note: This feature is for ZScript only.

(New from 2.4.0)
Dynamic arrays are resizable versions of regular arrays, with built-in functions to allow easy management.

The types available are:

  • Double
  • Int
  • String
  • Pointer (i.e. Actor)

To declare a dynamic array, it must be done in a class's global space:

Class example
{
    Array<type> myArray;
}

Functions

  • uint Size();
Returns the size of the array.
  • void Copy(Array<type> other);
Replaces the array's contents with the contents of the specified other array.
  • void Move(Array<type> other);
Transfers the contents of an array to another variable. Imagine a function building an array and finally storing it somewhere else.
  • uint Find(<type> item);
Searches for a particular item of the array's type and returns the index of that item. If the item is not found in the array, returns Size().
  • uint Push (<type> item);
Appends item to the end of the array and expands it by one.
  • bool Pop ();
Destroys the item at the end of the array and decreases its size by one.
  • void Delete (uint index, int deletecount = 1);
Removes a range of entries from the array.
  • void Insert (uint index, <type>item);
Inserts an item at the specified index. (Whether this requires the array to be large enough or if the function performs a resize to accommodate has yet to be clarified.)
  • void ShrinkToFit ();
Shrinks the total array size to the last non-empty member's location.
  • void Grow (uint amount);
Increases the size of the array by the amount specified. (Where, I'm assuming is at the end.)
  • void Resize (uint amount);
Grows or shrinks the array to the exact amount. Destroys all content within the removed containers.
  • uint Reserve (uint amount);
Allocates 'amount' new entries and returns the index of the first one.
  • uint Max ();
Returns how many entries are allocated, also counting those which are currently not in use. Caution must be used here since this can return a number greater than the array's actual size itself.
  • void Clear ();
Shrinks the array to 0 and destroys all contents.

Examples

Nuvolachalk.png Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contibutions are greatly appreciated.