
David A. Gray, MBA
Chief Wizard, WizardWrx
WinBatch offers two mechanisms for processing lists, each of which is intended to solve a different set of problems involving collections of related data.
WinBatch provides rich sets of functions for manipulating both lists and arrays. The purpose of this paper is to explain the similarities and differences between lists and arrays and show how each is better suited to a different class of problems.
Lists are implemented as strings. List items are delimited by a specified character. The characteristics of a list derive from these two factors. Lists have the following characteristics.
Lists lend themselves to storing static lists such as small lookup tables, from which an item of interest is extracted by position, and lists, such as file lists, that are passed to dialog boxes.
Arrays are implemented as lists or tables of pointers to memory locations that contain the data. Unlike lists, there are no practical restrictions on the value of any array element. Arrays have the following characteristics.
Arrays work well for storing tables and matrices of data whose size is known in advance. For example, the 2003 versions and later of WIL contain functions that can read an entire CSV file into a matrix. Because they are implemented as pointer tables, arrays significantly outperform lists on large numbers (hundreds or thousands) of items. This applies even to locating items by number, because a list must be searched linearly to locate and extract the item.
The following table summarizes the differences between lists and arrays.
Property |
Lists |
Arrays |
Size |
Adjusts as items are added or removed. | Defined before first use. |
Allowable Characters in Data |
Any except item delimiter. |
Any. |
Adding or Removing Item |
Entire list must be copied to another memory location. |
Only new item is copied, and array pointer table updated with location of new item. |
Sorting Items |
Entire list must be copied at least once. |
Only small pointer table must be copied. |
Total memory requirement. |
Enough room to hold up to two copies of list. |
Enough room to hold all elements and up to two copies of pointer table. |