Application Data Manager (ADM) is an open source solution for processing large amounts of real-time data. In this segment I describe the ADM process for incrementally allocating memory to and sequencing large sets of objects.

# Unconstrained Array of Objects

In the previous segment I introduced the concept of an unconstrained array of numeric aliases called a Sequence. In this segment I extend the unconstrained array concept to a set of objects of generic class M.

## Unconstrained Array Declarations

A set is a number of things of the same kind that belong or are used together. In Java we can make things be of the same kind by requiring they be objects of the same class. Since we have no a priori knowledge of what that class is, we use the generic class T (type) and enclose T in angle brackets. Making this class be an extension of *Sequence* provides the means to add and recycle elements; moreover, implementing Iterable<T> means we can iterate over the order of appearance.

class UnconstrainedArray<M> extends Sequence implements Iterable<T> {

private T[] smallE;

private T[][] mediumE;

private T[][][] largeE;

⋮

`}`

### Case Small – The first 256 elements

Since the sequence and the unconstrained array must be in one-to-one correspondence, every allocation of 256 elements to the sequence requires a corresponding allocation of 256 instances of T. However, all 256 instances of T are initially null.

this.smallE = (T[])new Object[256];

An append method obtains an alias (i.e. index) from the sequence and then assigns a new instance of T at that index. The allocated memory is only as large as it needs to be and no larger.

### Case Medium – The next increment of 256 elements

For objects the transition from small to medium is a bit simpler than for sequences, taking only three lines of code:

this.mediumE = (T[][]) new Object[256][];

this.mediumE[0] = this.smallE; //note the continued use of smallE !!!

this.mediumE[1] = (T[]) new Object[256];

### Case Large – The 256th increment of 256 elements

When the capacity of mediumE is reached, largeE is allocated with the following code

this.largeE = (T[][][]) new Object[256][256][];

this.largeE[0] = this.mediumE; //note the continued use of mediumE !!!

this.largeE[1] = (T[][]) new Object[256][];

this.largeE[1][0] = (T[]) new Object[256];

### Summary

- The unconstrained array of objects T is a set
- The capacity of the set grows in increments of 256 elements to a maximum capacity of 16,777,216 elements.
- Addition and recycling are managed using the underlying Sequence.
- Each element of the underlying Sequence (an alias / index) is in one-to-one correspondence with an element of set T
- The underlying sequence enumerates the set of T.
- Every element of set T is accessible via its alias.
- Iteration over the order of appearance is supported.

In the next segment I will introduce unconstrained arrays of numeric data.

Copyright © 2014 Color My Data, All Rights Reserved