X++ Standards: Arrays


This topic describes the best practice for using the memory option in arrays. For more information, see Arrays.
The memory option is the optional second array declaration option. It specifies how many consecutive entries in the array will be held in memory at a particular time. The rest will reside on disk (a cached temporary file, indexed by the array index).
Dynamic arrays are sized according to the maximum index used.
TipTip
Use the memory option to limit the amount of RAM used to hold the data of the array when you work with high numbered indexes (and large cells).
If you use all (or nearly all) of the entries in an array, set the memory option to a large number, or do not set it at all.
If you only use a few of the entries in the array, set the memory option to a small number, such as 1.
If you consider using the memory option on an array where you use all (or almost all) of the entries, the look up performance should be considered.
If you traverse an array sequentially, such as with an index of 1, 2, 3, ..., n, you will probably not experience any read performance problems. The cell data blocks will be read sequentially from disk and they will be read to the end before the next block is read (disk reads will be number of entries/memory option size).
If you traverse an array randomly (such as with an index of 300, 20, 5, 250, n, ..., 50) the cell data will also be read from disk randomly, so you may experience read performance problems (disk reads could be as high as the number of entries).

Example 1

MyTable myTable;
boolean foundRecord[,1];
;
while select myTable
where myTable
...
{
foundRecord[myTable.recId] = true;
...
}

Example 2

CustTable custTable;
CustAccount foundAccount[];
int i;
;
while select custTable
where custTable
...
{
i++;
foundAccount[i] = custTable.AccountNum;
...
}

Example 3

Name foundName[,100];
int i;
;
while select custTable
where custTable
...
{
i++;
foundName[i] = custTable.Name;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.