Class LargeMemoryModel<P>

java.lang.Object
net.algart.arrays.AbstractMemoryModel
net.algart.arrays.LargeMemoryModel<P>
All Implemented Interfaces:
MemoryModel

public final class LargeMemoryModel<P> extends AbstractMemoryModel

The memory model, storing array elements in an external file.

The idea of this model is alike mapping files by standard FileChannel.map method. But this model has two important advantages.

First, here is no 32-bit restriction for the number of elements. AlgART arrays use 64-bit element addressing. So, an AlgART array created by this memory model can be as large as the files can. In practice it means that the array size is limited only by available disk space.

Second, the external files are represented by special abstraction named "Data File Models" (DataFileModel interface). This "data file" abstraction is much more simple than RandomAccessFile and similar classes, usually representing disk files. The are two ready implementations DefaultDataFileModel and StandardIODataFileModel, really corresponding to disk files; but it's not a problem to create custom implementation of the data file, that will correspond to almost any type of an external storage. For example, it's possible to create very trivial implementation, that will interpret a usual byte[] array or String object as a "data file". More useful implementations may provide access, for example, to BufferedImage or another existing storage as to an AlgART array.

Unlike the simple memory model, this model supports primitive element types only: BitArray, CharArray, ByteArray, ShortArray, IntArray, LongArray, FloatArray, DoubleArray. If you need to store objects in external data files, you may use the AlgART arrays, created by this memory model, as a storage for combined arrays, created by CombinedMemoryModel.

The maximal theoretical limit for length and capacity of AlgART arrays, supported by this memory model, is 263-64 for bit arrays and 263/size-1 for all other element types, where size is 1,2,2,4,8,4,8 for element types byte, char, short, int, long, float, double correspondingly.

Arrays, created by this memory model, never implement DirectAccessible interface.

This memory model creates a new array with help of DataFileModel.createTemporary(boolean) method, that allocates new data file. Immediately after this call, the newly created data file is opened via DataFile.open(false) call and, then, truncated to the DataFileModel.recommendedPrefixSize() bytes by DataFile.length(long) call. (After this, if necessary, the file length will be increased by length(long) according to the array length.) Due to the contract of DataFile.open(boolean) method, it means that the file will always exists right now after allocating a new array: even if the custom, non-standard implementation of DataFileModel does not really create new file in DataFileModel.createTemporary(boolean), it will be created by further open(false) call.

Further possible views of the created array, for example, its subarrays or immutable view, will use the same underlying data file.

A resizable array, created by this memory model (newArray(Class, long), newEmptyArray(Class, long), newEmptyArray(Class) methods), always uses the same data file, even after resizing. Increasing the array length, when necessary, leads to increasing the underlying data file length (DataFile.length(long) method). (Please compare: resizing arrays, created by SimpleMemoryModel / BufferMemoryModel, can lead to reallocation of the Java array / ByteBuffer and copying elements to new array / ByteBuffer.) But the contrary assertion is not true: reducing the array size never leads to reducing the data file length. In other words, the data file length only increases, but never decreases.

Moreover, for a resizable array, the length of the data file is always multiple of DataFileModel.recommendedBankSize(false) and is increased by this step. It means that resizable arrays may be not efficient enough for storing little number of elements. Unlike this, an unresizable array, created by this memory model (newUnresizableArray(Class, long), newMatrix(Class, Class, long...), valueOf(Object), etc.), allocates data file with almost minimal length that is enough for storing all array elements.

When the data file becomes unused, because there are no active AlgART array instances based on it, it is automatically delete by garbage collector with help of DataFileModel.delete(DataFile) method. (The only exception is a case if you've called setTemporary(largeArray, false) for this array.)

You may also view an existing data file as an AlgART array via asArray and asUpdatableArray methods of this class.

Arrays, created by this memory model, have non-trivial implementation of Array.loadResources(ArrayContext), Array.flushResources(ArrayContext), Array.flushResources(ArrayContext, boolean) and Array.freeResources(ArrayContext, boolean) methods: Namely:

This class has the generic argument P, that describes data file paths in the data file model used by this memory model. The getInstance() factory method always returns a file-oriented instance, where P is java.io.File. But the getInstance(DataFileModel) factory method allows to create a memory model for any generic type P.

This class is immutable and thread-safe: there are no ways to modify settings of its instance returned by getInstance() or getInstance(DataFileModel) methods.

Author:
Daniel Alievsky
  • Field Details

    • CONSTANT_PROPERTY_NAME

      public static final String CONSTANT_PROPERTY_NAME
      See Also:
    • TILE_DIMENSIONS_PROPERTY_NAME

      public static final String TILE_DIMENSIONS_PROPERTY_NAME
      See Also:
    • ALL_FILE

      public static final long ALL_FILE
      The special value for fileAreaSize argument in asArray and asUpdatableArray methods, that means the region from the specified position to the file end. Please note that this value is not applicable for asUpdatableArray method when its truncate argument is true or if the current file length is less than filePosition argument: in these cases, ALL_FILE value is equivalent to 0.
      See Also:
  • Method Details

    • getInstance

      public static LargeMemoryModel<File> getInstance()
      Returns default instance of this memory model.

      This instance uses some standard data file model, that is determined while initializing this class from the system property "net.algart.arrays.LargeMemoryModel.dataFileModel". This property must contain the full name of the Java class implementing MemoryModel interface. The class must have a public constructor without arguments or, as a variant, static getInstance() method without arguments returning an instance of this memory model. Moreover, the class of data file paths, used by this model (DataFileModel.pathClass()), must be java.io.File. This constructor or getInstance() method will be used for creating the data model instance.

      If there is not such system property, or if some of described conditions is not fulfilled, the DefaultDataFileModel will be used as the data file model.

      The following standard aliases are allowed for the class name in "net.algart.arrays.LargeMemoryModel.dataFileModel" system property:

      Returns:
      default instance of this memory model.
    • getInstance

      public static <P> LargeMemoryModel<P> getInstance(DataFileModel<P> dataFileModel)
      Returns new instance of this memory model for the specified data file model.
      Parameters:
      dataFileModel - the data file model that will be used by this memory model instance.
      Returns:
      new instance of this memory model.
    • getDataFileModel

      public DataFileModel<P> getDataFileModel()
      Returns a reference to the data file model used by this memory model instance.
      Returns:
      a reference to the data file model used by this memory model instance.
      See Also:
    • newEmptyArray

      public MutableArray newEmptyArray(Class<?> elementType)
      Description copied from interface: MemoryModel
      Allocates an empty resizable array with the specified element type and a little initial capacity. It is equivalent to newEmptyArray(elementType, n), where n is some little value.

      Example of usage:

           MutableFloatArray a = (MutableFloatArray)memoryModel.newEmptyArray(float.class);
       
      Specified by:
      newEmptyArray in interface MemoryModel
      Specified by:
      newEmptyArray in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      Returns:
      created AlgART array.
      See Also:
    • newEmptyArray

      public MutableArray newEmptyArray(Class<?> elementType, long initialCapacity)
      Description copied from interface: MemoryModel
      Allocates an empty resizable array with the specified element type and initial capacity.

      The element type can be either usual object class (as String.class), or one of the primitive types: boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class, char.class. The element type cannot be void.class.

      In a case of primitive types, the created array will implement the corresponding interface BitArray, ByteArray, ShortArray, IntArray, LongArray, FloatArray, DoubleArray or CharArray. In this case, the created array (unlike standard ArrayList) will occupy the same amount of memory as the Java array boolean[initialCapacity], byte[initialCapacity], etc.

      In a case of non-primitive types (Object inheritors), the created array will implement the MutableObjectArray interface.

      Some element type may be not supported by this memory model. For example, some memory models may support only primitive types, or only one concrete type. In such a case, UnsupportedElementTypeException will be thrown.

      Some too large array capacities may be not supported by this memory model. For example, SimpleMemoryModel does not support arrays larger than 0x7FFFFFFF (Integer.MAX_VALUE) elements.

      Example of usage:

           MutableFloatArray a = (MutableFloatArray)memoryModel.newEmptyArray(float.class, 10000);
       
      Specified by:
      newEmptyArray in interface MemoryModel
      Specified by:
      newEmptyArray in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      initialCapacity - the initial capacity of the array.
      Returns:
      created AlgART array.
      See Also:
    • newArray

      public MutableArray newArray(Class<?> elementType, long initialLength)
      Description copied from interface: MemoryModel
      Allocates a zero-filled resizable array with the specified element type and initial length. The capacity of new array will be equal to its length.

      This method is equivalent to the following call: newEmptyArray(elementType, initialLength).length(initialLength).trim().

      Specified by:
      newArray in interface MemoryModel
      Specified by:
      newArray in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      initialLength - the initial length and capacity of the array.
      Returns:
      created AlgART array.
      See Also:
    • newUnresizableArray

      public UpdatableArray newUnresizableArray(Class<?> elementType, long length)
      Description copied from interface: MemoryModel
      Allocates a zero-filled unresizable array with the specified element type and length. The capacity of new array will be equal to its length.

      The analogous result may be obtained the following call: newArray(elementType, length).asUnresizable(). However, we don't recommend to use such code. If you are sure that you will not need to change the array length, please always use this method (or newUnresizableBitArray, newUnresizableBteArray, etc.). In some memory models, creating resizable array with the given length may require much more resources that creating unresizable one. For example, in the large memory model every resizable array is stored in the file consisting of integer number of blocks per DataFileModel.recommendedBankSize(true) bytes.

      Specified by:
      newUnresizableArray in interface MemoryModel
      Specified by:
      newUnresizableArray in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      length - the length and capacity of the array.
      Returns:
      created unresizable AlgART array.
      See Also:
    • isElementTypeSupported

      public boolean isElementTypeSupported(Class<?> elementType)
      Description copied from interface: MemoryModel
      Returns true if this memory model can create arrays with this element type. If it does not support it, creation methods of this memory model will throw UnsupportedElementTypeException. The result is not defined for void.class.
      Specified by:
      isElementTypeSupported in interface MemoryModel
      Specified by:
      isElementTypeSupported in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      Returns:
      true if this memory model supports this element type.
    • areAllPrimitiveElementTypesSupported

      public boolean areAllPrimitiveElementTypesSupported()
      Description copied from interface: MemoryModel
      Returns true if this memory model can create arrays with all primitive element types: boolean, char, byte, short, int, long, float, double.
      Specified by:
      areAllPrimitiveElementTypesSupported in interface MemoryModel
      Specified by:
      areAllPrimitiveElementTypesSupported in class AbstractMemoryModel
      Returns:
      true if this memory model supports all primitive element types.
      See Also:
    • areAllElementTypesSupported

      public boolean areAllElementTypesSupported()
      Description copied from interface: MemoryModel
      Returns true if this memory model can create arrays with all element types. This package offers only one such memory model: SimpleMemoryModel.
      Specified by:
      areAllElementTypesSupported in interface MemoryModel
      Specified by:
      areAllElementTypesSupported in class AbstractMemoryModel
      Returns:
      true if this memory model supports element types.
      See Also:
    • maxSupportedLength

      public long maxSupportedLength(Class<?> elementType)
      Description copied from interface: MemoryModel
      Returnes maximal possible length of arrays with the specified element type supported by this memory model. If the capacity / length passed to MemoryModel.newEmptyArray(Class, long) / MemoryModel.newArray(Class, long) methods is greater than the result of this method, they will throw TooLargeArrayException. The result is not defined it the passed element type is not supported by this memory model (for example, it may be -1).

      For some memory model, the method may be not enough informative: creation methods may throw TooLargeArrayException even if the passed capacity / length is less than the result of this method. Please refer to the documentation of the corresponding memory model to know the precise behavior of this method. In any case, maximal possible array length is restricted by the amount of Java memory.

      Specified by:
      maxSupportedLength in interface MemoryModel
      Specified by:
      maxSupportedLength in class AbstractMemoryModel
      Parameters:
      elementType - the type of array elements.
      Returns:
      maximal possible length of arrays supported by this memory model.
    • isCreatedBy

      public boolean isCreatedBy(Array array)
      Description copied from interface: MemoryModel
      Returns true if the passed array was created by this (or identical) memory model.

      For SimpleMemoryModel and BufferMemoryModel, "identical" means the same memory model.

      For LargeMemoryModel, "identical" means that the memory model is also large and was created with the same instance of the data file factory.

      For CombinedMemoryModel, "identical" means that the memory model is also combined and was created with the same instance of the combiner.

      Returns false if the passed argument is null.

      Specified by:
      isCreatedBy in interface MemoryModel
      Specified by:
      isCreatedBy in class AbstractMemoryModel
      Parameters:
      array - the AlgART array (may be null, than the method returns false).
      Returns:
      true if the passed array was created by this memory model.
    • isLargeArray

      public static boolean isLargeArray(Array array)
      Returns true if the passed array was created by some instance of this memory model. Returns false if the passed array is null or an AlgART array created by another memory model.
      Parameters:
      array - the checked array (may be null, than the method returns false).
      Returns:
      true if this array is a large array created by a large memory model.
    • isTemporary

      public static boolean isTemporary(Array largeArray)
      Returns true is the passed array is temporary, that is if the corresponded data file storing all its elements will be automatically deleted when this AlgART array and all other arrays, sharing the same data (as subarrays), will become unreachable and will be finalized.

      Usually this flag is true, if the array was created in the normal way via newArray(Class, long) and similar methods, and false, it the arrays was created as a view of some external file by asArray or asUpdatableArray methods. However, you may change this flag via setTemporary(Array, boolean) method.

      The passed argument must be created by the large memory model: isLargeArray(Array) must return true. In other case, IllegalArgumentException will be thrown.

      Parameters:
      largeArray - the AlgART array.
      Returns:
      true if the corresponded data file is temporary and should be automatically deleted.
      Throws:
      NullPointerException - if largeArray is null.
      IllegalArgumentException - if largeArray is not large array (i.e. is not create by a large memory model).
    • setTemporary

      public static void setTemporary(Array largeArray, boolean value)
      Changes temporary status, returned by isTemporary(Array) method.

      When value=false, this method allows to prevent from deletion of the data file containing results of some algorithm, which created an array with usual newArray(Class, long) or similar method. In this case, please not forget to call largeArray.flushResources(context) after completion of filling this array; in other case, some array elements can be lost while further garbage collection or JVM termination.

      When value=true, this method allows to safely delete the external data file, mapped to an AlgART array via asArray or asUpdatableArray methods, when the last mapping will be successfully closed.

      This method also sets the temporary flag for all arrays, that share data with this one.

      The passed argument must be created by the large memory model: isLargeArray(net.algart.arrays.Array) must return true. In other case, IllegalArgumentException will be thrown.

      Parameters:
      largeArray - the AlgART array.
      value - new temporary status for this array.
      Throws:
      NullPointerException - if largeArray is null.
      IllegalArgumentException - if largeArray is not large array (i.e. is not create by a large memory model).
    • getDataFileModel

      public static DataFileModel<?> getDataFileModel(Array largeArray)
      Returns the model of the data file storing all elements of the passed AlgART array.

      The passed argument must be created by the large memory model: isLargeArray(Array) must return true. In other case, IllegalArgumentException will be thrown.

      Parameters:
      largeArray - the AlgART array.
      Returns:
      the data file model used in this array.
      Throws:
      NullPointerException - if largeArray is null.
      IllegalArgumentException - if largeArray is not large array (i.e. is not create by a large memory model).
    • getDataFilePath

      public P getDataFilePath(Array largeArray)
      Returns the path to the data file storing all elements of the passed AlgART array.

      Note: returned data file may contain extra data besides the content of the passed AlgART array.

      Note: you should not try to work with the returned file until full JVM exit! The data file, used by this array, may be opened and accessed until the moment, when all connected Java objects will be successfully finalized by the garbage collector, and there is no guarantee that it will occur at all. So, the results of attempts of simultaneous access this file from your code are unspecified.

      But you may use this method for storing file name somewhere, to open it again on the next application start via asArray or asUpdatableArray methods.

      The passed argument must be created by the large memory model: isLargeArray(Array) must return true. In other case, IllegalArgumentException will be thrown.

      The passed argument may be created by another instance of the large memory model than this one. But the data file model of that memory model, which was used for creating the passed array, must use the same class (or an inheritor) for data file paths (see DataFileModel.pathClass()), as the data file model of this large memory model. In other case, ClassCastException will be thrown.

      Parameters:
      largeArray - the AlgART array.
      Returns:
      the data file model used in this array.
      Throws:
      NullPointerException - if largeArray is null.
      IllegalArgumentException - if largeArray is not large array (i.e. is not created by a large memory model).
      ClassCastException - if largeArray is created by the large memory model, based on illegal data file model (incompatible with the required P type of data file paths).
    • cast

      public <U> LargeMemoryModel<U> cast(Class<U> pathClass)
      Returns this memory model, cast to the specified generic type of the data file paths, or throws ClassCastException if the current type getDataFileModel().pathClass() cannot be cast to the passed type pathClass. This method always returns the reference to this instance and is compiled without "unchecked cast" warning.
      Parameters:
      pathClass - the type of the data file paths in the returned memory model.
      Returns:
      this memory model, cast to the required type of the data file paths.
      Throws:
      NullPointerException - if the argument is null.
      ClassCastException - if the current type of the data file paths cannot be cast to the required type.
    • isCreatedReadOnly

      public static boolean isCreatedReadOnly(Array largeArray)
      Returns true if the passed large array was created by asArray(Object, Class, long, long, ByteOrder) method or one of its versions for concrete element types (asBitArray(Object, long, long, ByteOrder), asCharArray(Object, long, long, ByteOrder), etc.), or if the passed argument is a view of such an array.

      This method allows to check whether the original array, reflecting some external data file, was created immutable. If (and only if) this method returns true, you can be sure that this array and, moreover, all AlgART arrays, possibly sharing the data with this one, are immutable.

      (The only way to create such "strongly immutable" array is using asArray(Object, Class, long, long, ByteOrder) method and its versions for concrete element types. Usually, an AlgART array is created updatable via allocation methods of MemoryModel, and only some its views, created with help of Array.asImmutable() method, are immutable.)

      The passed argument must be created by the large memory model: isLargeArray(Array) must return true. In other case, IllegalArgumentException will be thrown.

      Parameters:
      largeArray - the AlgART array.
      Returns:
      true if this array and any other arrays, sharing data with it, are immutable.
      Throws:
      NullPointerException - if largeArray is null.
      IllegalArgumentException - if largeArray is not large array (i.e. is not created by a large memory model).
    • asArray

      public PArray asArray(P filePath, Class<?> elementType, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Returns an immutable AlgART array with specified element type, backed by the content of a region of the data file with specified name. To access the file, this method will convert the filePath to DataFile instance by dataFileModel.getDataFile(filePath,byteOrder) call, where dataFileModel is the current data file model used by this memory model instance.

      The array element #0 will correspond to the byte #filePosition of the file. So, for bit array, the bit #0 of the resulting array will be the low bit of the byte value at the specified position (value&0x1); for int array, the int element #0 will occupy the bytes #filePosition..#filePosition+3; etc.

      The length of the returned array will be equal to fileAreaSize/bytesPerElement, where bytesPerElement is 2, 1, 2, 4, 8, 4, 8 for array of char, byte, short, int, long, float, double correspondingly. For a case of bit array, the length of the returned array will be equal to (fileAreaSize/8)*64. So, all array content never exceeds the specified range filePosition..filePosition+fileAreaSize-1, but several bytes at the end of this range may be unused.

      If the end of specified region, filePosition+fileAreaSize, exceeds the current file length, the IndexOutOfBoundsException is thrown.

      The fileAreaSize is equal to the special value ALL_FILE, then it is automatically replaced with fileLength-filePosition, where fileLength is the current file length in bytes. So, you may pass 0 as filePosition and ALL_FILE value as fileAreaSize to view all the file as an AlgART array.

      In all cases besides an array of bytes, the order of bytes in every array element, placed in the file, or in some group of elements (probably 64) in a case of bit array, is specified by byteOrder argument. However, for bit array, the order of bits inside every byte is always "little endian": the element #k in the returned bit array corresponds to the bit byteValue&(1<<(k%8)), where byteValue is a byte at position depending on byteOrder.

      This method opens the data file in read-only mode by DataFile.open(true) method.

      If the data file with the specified path filePath does not exist yet, FileNotFoundException is thrown.

      After calling this method, you should not operate with this file in another ways than using returned AlgART array, else the results ot such operations will be unspecified.

      Please note: the returned AlgART array may work faster than an updatable array returned by asUpdatableArray(P, java.lang.Class<?>, long, long, boolean, java.nio.ByteOrder) for the same file.

      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      elementType - the type of array elements.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath, elementType or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative or if fileAreaSize is negative and not equal to ALL_FILE.
      IndexOutOfBoundsException - if the specified region exceeds the current file length.
      See Also:
    • asUpdatableArray

      public UpdatablePArray asUpdatableArray(P filePath, Class<?> elementType, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Returns an unresizable AlgART array with specified element type, backed by the content of a region of the data file with specified name. To access the file, this method will convert the filePath to DataFile instance by dataFileModel.getDataFile(filePath,byteOrder) call, where dataFileModel is the current data file model used by this memory model instance.

      The changes performed in the returned array will be reflected in the specified data file. But the changed data can be not really stored at the external device until you call Array.flushResources or Array.freeResources method.

      The array element #0 will correspond to the byte #filePosition of the file. So, for bit array, the bit #0 of the resulting array will be the low bit of the byte value at the specified position (value&0x1); for int array, the int element #0 will occupy the bytes #filePosition..#filePosition+3; etc.

      The length of the returned array will be equal to fileAreaSize/bytesPerElement, where bytesPerElement is 2, 1, 2, 4, 8, 4, 8 for array of char, byte, short, int, long, float, double correspondingly. For a case of bit array, the length of the returned array will be equal to (fileAreaSize/8)*64. So, all array content never exceeds the specified range filePosition..filePosition+fileAreaSize-1, but several bytes at the end of this range may be unused.

      If the end of specified region (filePosition+fileAreaSize) exceeds the current file length, or if the truncate argument is true, the file length is automatically set to the filePosition+fileAreaSize bytes.

      The fileAreaSize is equal to the special value ALL_FILE, then it is automatically replaced with fileLength-filePosition, where fileLength is the current file length in bytes. So, you may pass 0 as filePosition and ALL_FILE value as fileAreaSize to view all the file as an AlgART array. In this case, if the current file length is less than filePosition or the truncate argument is true, the file length is automatically set to filePosition.

      In all cases besides an array of bytes, the order of bytes in every array element, placed in the file, or in some group of elements (probably 64) in a case of bit array, is specified by byteOrder argument. However, for bit array, the order of bits inside every byte is always "little endian": the element #k in the returned bit array corresponds to the bit byteValue&(1<<(k%8)), where byteValue is a byte at position depending on byteOrder.

      This method opens the data file in read-write mode by DataFile.open(false) method.

      If the data file with the specified path filePath does not exist yet, this method tries to create it at the specified path (see comments to DataFile.open(boolean)). In this case, the initial file length is set to filePosition+fileAreaSize, and the initial file content is unspecified. If fileAreaSize=ALL_FILE, the results will be the same as if fileAreaSize=0.

      After calling this method, you should not operate with this file in another ways than using returned AlgART array, else the results ot such operations will be unspecified.

      Please note: the returned AlgART array may work slower than an immutable array returned by asArray(P, java.lang.Class<?>, long, long, java.nio.ByteOrder) for the same file. If you need only reading the returned array, you should prefer asArray method.

      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      elementType - the type of array elements.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath, elementType or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative or if fileAreaSize is negative and not equal to ALL_FILE.
      See Also:
    • asBitArray

      public BitArray asBitArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableBitArray

      public UpdatableBitArray asUpdatableBitArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asCharArray

      public CharArray asCharArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableCharArray

      public UpdatableCharArray asUpdatableCharArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asByteArray

      public ByteArray asByteArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Equivalent to (ByteArray)asArray(filePath, byte.class, filePosition, fileAreaSize, byteOrder).

      In current implementation, byteOrder argument is not used in any way.

      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.

      In current implementation, byteOrder argument is not used in any way.

      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableByteArray

      public UpdatableByteArray asUpdatableByteArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Equivalent to (UpdatableByteArray)asUpdatableArray(filePath, byte.class, filePosition, fileAreaSize, byteOrder).

      In current implementation, byteOrder argument is not used in any way.

      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.

      In current implementation, byteOrder argument is not used in any way.

      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asShortArray

      public ShortArray asShortArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableShortArray

      public UpdatableShortArray asUpdatableShortArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asIntArray

      public IntArray asIntArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableIntArray

      public UpdatableIntArray asUpdatableIntArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asLongArray

      public LongArray asLongArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableLongArray

      public UpdatableLongArray asUpdatableLongArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asFloatArray

      public FloatArray asFloatArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableFloatArray

      public UpdatableFloatArray asUpdatableFloatArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asDoubleArray

      public DoubleArray asDoubleArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asUpdatableDoubleArray

      public UpdatableDoubleArray asUpdatableDoubleArray(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException
      Parameters:
      filePath - the name of data file that will be viewed as an AlgART array.
      filePosition - the starting position of the viewed region in the data file, in bytes.
      fileAreaSize - the size of the viewed region in the data file, in bytes.
      truncate - if true, the file length is always set to filePosition+fileAreaSize (or to filePosition if fileAreaSize==ALL_FILE); if false, the file length is set to this value only if it is greater than the current file length.
      byteOrder - the byte order that will be used for accessing the data file.
      Returns:
      a view of the specified region of the data file as an AlgART array.
      Throws:
      IOException - if some I/O error occurred while opening the file. (In a case of any I/O problems while further accesses to returned array, java.io.IOError will be thrown instead of IOException.)
      NullPointerException - if filePath or byteOrder argument is null.
      IllegalArgumentException - if filePosition is negative, if fileAreaSize is negative and not equal to ALL_FILE, or if the specified region exceeds the current file length.
    • asConstantMatrix

      public static Matrix<? extends PArray> asConstantMatrix(MatrixInfo matrixInfo) throws IllegalInfoSyntaxException
      Throws:
      IllegalInfoSyntaxException
    • asMatrix

      public Matrix<? extends PArray> asMatrix(P filePath, MatrixInfo matrixInfo) throws IOException, IllegalInfoSyntaxException
      Throws:
      IOException
      IllegalInfoSyntaxException
    • asUpdatableMatrix

      public Matrix<? extends UpdatablePArray> asUpdatableMatrix(P filePath, MatrixInfo matrixInfo) throws IOException, IllegalInfoSyntaxException
      Throws:
      IOException
      IllegalInfoSyntaxException
    • getMatrixInfoForSavingInFile

      public static MatrixInfo getMatrixInfoForSavingInFile(Matrix<? extends PArray> matrix, long dataOffset)
    • getRawArrayForSavingInFile

      public static PArray getRawArrayForSavingInFile(Matrix<? extends PArray> matrix)
    • newLazyCopy

      public MutableArray newLazyCopy(Array array)
      See comments to MemoryModel.newLazyCopy(Array) method.
      Specified by:
      newLazyCopy in interface MemoryModel
      Overrides:
      newLazyCopy in class AbstractMemoryModel
      Parameters:
      array - the source array.
      Returns:
      the lazy copy of the source array.
      Throws:
      NullPointerException - if the argument is null.
      UnsupportedElementTypeException - if the element type of the passed array is not supported by this memory model.
    • newUnresizableLazyCopy

      public UpdatableArray newUnresizableLazyCopy(Array array)
      Specified by:
      newUnresizableLazyCopy in interface MemoryModel
      Overrides:
      newUnresizableLazyCopy in class AbstractMemoryModel
      Parameters:
      array - the source array.
      Returns:
      the lazy unresizable copy of the source array.
      Throws:
      NullPointerException - if the argument is null.
      UnsupportedElementTypeException - if the element type of the passed array is not supported by this memory model.
    • activeFinalizationTasksCount

      public static int activeFinalizationTasksCount()
      Returns the current number of internal finalization tasks that are scheduled by this model to free unused system resources, but are not fully performed yet.

      If all tasks are performed, returns 0. In this case, for example, you can be sure that all temporary files, created by this memory model for storing AlgART arrays, are already removed. You may use this fact to create a method working alike Arrays.gcAndAwaitFinalization(int).

      Returns:
      the current number of finalization tasks, that are not performed yet.
    • activeArrayFinalizationTasksCount

      public static int activeArrayFinalizationTasksCount()
      Returns the current number of AlgART arrays that were created by not finalized yet by this model. While this value is non-zero, the number of internal finalization tasks cannot become zero. This information may be useful for debugging.
      Returns:
      the current number of AlgART arrays, created by this model, but not deallocated by the garbage collector yet.
    • activeMappingFinalizationTasksCount

      public static int activeMappingFinalizationTasksCount()
      Returns the current number of mapped blocks that were created by not finalized yet by this model. While this value is non-zero, the number of internal finalization tasks cannot become zero. This information may be useful for debugging.
      Returns:
      the current number of mapped blocks, created by this model, but not deallocated by the garbage collector yet.
    • allUsedDataFileModelsWithAutoDeletion

      public static Set<DataFileModel<?>> allUsedDataFileModelsWithAutoDeletion()
      Returns a newly allocated copy of the set of all data file models, that were used in any instances of this class (as constructor agruments) since the application start. The data file model is included into this set only if its DataFileModel.isAutoDeletionRequested() method returns true.

      If some instance of data file model is absolutely unreachable, because it was utilized by the garbage collector, and there are no any AlgART arrays using this data file model, then this instance may be excluded from this set. (The reason is that the used data file models are registered in a global collection via weak references, to avoid possible memory leak while creating a lot of instances of this class.)

      This method can be used together with DataFileModel.allTemporaryFiles() to get a list of all temporary files created by this package and not deleted yet.

      Returns:
      a newly allocated copy of the set of all used data file models.
    • toString

      public String toString()
      Returns a brief string description of this memory model.

      The result of this method may depend on implementation and usually contains information anout the used bank size and number of banks.

      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.