Categories of arrays in programming languages

Five array categories

The definitions of the categories are based on the binding to subscript value ranges and the binding to storage. The category names indicate where and when storage is allocated. Here are the five categories of arrays.

Static array

In a static array, the subscript ranges are statically bound and the storage allocation is static, which means it is done before run time. The advantage here is efficiency, since no dynamic allocation or deallocation is required.

Fixed stack-dynamic array

In a fixed stack-dynamic array, the subscript ranges are statically bound while the allocation is done at declaration elaboration during execution.The advantage here over static arrays is space efficiency. Two large arrays in different subprograms can share the same space, as long as the subprograms aren't active at the same time.

Stack-dynamic array

In a stack-dynamic array, the subscript ranges are dynamically bound and the storage allocation is dynamic, which means it is done during run time. The subscript ranges and the storage allocation remain fixed during the lifetime of the variable however when they are bound and allocated. The size of an array doesn't need to be known until the array is about to be used. The advantage over static arrays and fixed stack-dynamic arrays is flexibility.

Fixed heap-dynamic array

In a fixed heap-dynamic array, the subscript ranges are dynamically bound and the storage binding dynamic, like in the stack-dynamic array. When the storage is allocated though, they are both fixed.The differences are that the bindings are done when the user program requests them rather than at elaboration time, and the storage is allocated from the heap, as the name suggests, rather than the stack.

Heap-dynamic array

In a heap-dynamic array, the binding of the subscript ranges and storage allocation is dynamic, and can change during the array's lifetime. The advantage of heap-dynamic array over all of the others is flexibility. It can grow and shrink whenever needed.

Author

authors profile photo