CompressMemoryUsedBy
CompressMemoryUsedBy(A)
In some cases, this function is able to reduce the amount of memory consumed by array «A». The logical contents of «A» is unchanged, so you won't see a difference, other than possibly a drop in memory usage.
In Analytica's internal representation of arrays, it is able to represent certain types of sparseness. There are basically two forms that may occur: Shared subarrays and constant subvectors.
A shared subarray might occur from an expression such as:
Array(I, [A, A, A, B, B])
Under certain conditions (specifically, when I
comes before all indexes of A
and B
in Analytica's internal canonical index order), the first three slices along I
are the same subarray, allowing Analytica to store it only once and not three times. Likewise, the last two slices along I
share a subarray.
If the same array were created through a different sequence of operations, you might end up with a dense array, with every cell explicitly stored. Under normal operations Analytica does not explicitly detect subarrays that could be potentially shared, since this can be a very expensive operation. CompressMemoryUsedBy detects these and converts the internal representation into one that shares these common subarrays to save memory.
The second type of sparseness, constant subvectors, occurs when all slices along an index contain precisely the same value. For example, in the array:
J ▶ | ||||
---|---|---|---|---|
I ▼ | 3 | 5 | 7 | 6 |
8 | 8 | 8 | 8 | |
4 | 4 | 4 | 4 |
When the I
index is before J
in Analytica's internal canonical index order, then the last two slices along I
are constant along J
. Analytica saves memory (and computation time when this is used in a downstream computation) by storing the value 8 only once, and storing the value 4 only once. Hence in this example, only 6 cells of the original 12 consume memory like this:
J ▶ | ||||
---|---|---|---|---|
I ▼ | 3 | 5 | 7 | 6 |
8 | ||||
4 |
CompressMemoryUsedBy recognizes constant-vector sparseness and replaces the original by a sparse vector when this is detected.
CompressMemoryUsedBy also detects identical text strings when they occur in the same innermost vector, and changes these to share the same text. However, it does not detect identical text strings in arbitrary points in the array (this is for space-time efficiency).
History
This function was introduced in Analytica 4.3.
See Also
- MemoryInUseBy(A) -- to monitor the amount of memory consumed.
- Memory usage and management
- Memory Usage Dialog
Enable comment auto-refresher