Class LargeMemoryModel<P>
- All Implemented Interfaces:
MemoryModel
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:
Array.loadResources(context)
loads the beginning of the current array from the data file and callsDataFile.BufferHolder.load()
for the corresponding mapping in the data file.Array.flushResources(context, false)
andArray.flushResources(context)
callDataFile.BufferHolder.flush(false)
for all active mappings in the data file.Array.flushResources(context, true)
callsDataFile.force()
for the underlying data file andDataFile.BufferHolder.flush(true)
for all active mappings in the data file.Array.freeResources(context, false)
callsDataFile.close()
for the underlying data file andDataFile.BufferHolder.flush(false)
for all active mappings in the data file. Please note that it does not guarantee that this all system resources, associated with this data file, will be compeletely released. For example, the disk file can remain opened. If you need to be sure that all system resources, as file handles, will be freed by this method, you may useStandardIODataFileModel
.Array.freeResources(context, true)
callsDataFile.force()
andDataFile.close()
for the underlying data file andDataFile.BufferHolder.flush(true)
for all active mappings in the data file.
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 Summary
Modifier and TypeFieldDescriptionstatic final long
The special value for fileAreaSize argument inasArray
andasUpdatableArray
methods, that means the region from the specified position to the file end.static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Returns the current number of AlgART arrays that were created by not finalized yet by this model.static int
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.static int
Returns the current number ofmapped blocks
that were created by not finalized yet by this model.static Set<DataFileModel<?>>
Returns a newly allocated copy of the set of alldata file models
, that were used in any instances of this class (as constructor agruments) since the application start.boolean
Returns true if this memory model can create arrays with all element types.boolean
Returns true if this memory model can create arrays with all primitive element types: boolean, char, byte, short, int, long, float, double.asArray
(P filePath, Class<?> elementType, long filePosition, long fileAreaSize, ByteOrder byteOrder) asBitArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (BitArray)asArray(filePath, boolean.class, filePosition, fileAreaSize, byteOrder)
.asByteArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (ByteArray)asArray(filePath, byte.class, filePosition, fileAreaSize, byteOrder)
.asCharArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (CharArray)asArray(filePath, char.class, filePosition, fileAreaSize, byteOrder)
.asConstantMatrix
(MatrixInfo matrixInfo) asDoubleArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (DoubleArray)asArray(filePath, double.class, filePosition, fileAreaSize, byteOrder)
.asFloatArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (FloatArray)asArray(filePath, float.class, filePosition, fileAreaSize, byteOrder)
.asIntArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (IntArray)asArray(filePath, int.class, filePosition, fileAreaSize, byteOrder)
.asLongArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (LongArray)asArray(filePath, long.class, filePosition, fileAreaSize, byteOrder)
.asMatrix
(P filePath, MatrixInfo matrixInfo) asShortArray
(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) Equivalent to (ShortArray)asArray(filePath, short.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableArray
(P filePath, Class<?> elementType, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Returns anunresizable
AlgART array with specified element type, backed by the content of a region of thedata file
with specified name.asUpdatableBitArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableBitArray)asUpdatableArray(filePath, boolean.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableByteArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableByteArray)asUpdatableArray(filePath, byte.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableCharArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableCharArray)asUpdatableArray(filePath, char.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableDoubleArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableDoubleArray)asUpdatableArray(filePath, double.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableFloatArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableFloatArray)asUpdatableArray(filePath, float.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableIntArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableIntArray)asUpdatableArray(filePath, int.class, filePosition, fileAreaSize, byteOrder)
.asUpdatableLongArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableLongArray)asUpdatableArray(filePath, long.class, filePosition, fileAreaSize, byteOrder)
.Matrix<? extends UpdatablePArray>
asUpdatableMatrix
(P filePath, MatrixInfo matrixInfo) asUpdatableShortArray
(P filePath, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) Equivalent to (UpdatableShortArray)asUpdatableArray(filePath, short.class, filePosition, fileAreaSize, byteOrder)
.<U> LargeMemoryModel<U>
Returns this memory model, cast to the specified generic type of the data file paths, or throws ClassCastException if the current typegetDataFileModel()
.pathClass()
cannot be cast to the passed type pathClass.Returns a reference to the data file model used by this memory model instance.static DataFileModel<?>
getDataFileModel
(Array largeArray) getDataFilePath
(Array largeArray) static LargeMemoryModel<File>
Returns default instance of this memory model.static <P> LargeMemoryModel<P>
getInstance
(DataFileModel<P> dataFileModel) Returns new instance of this memory model for the specified data file model.static MatrixInfo
getMatrixInfoForSavingInFile
(Matrix<? extends PArray> matrix, long dataOffset) static PArray
getRawArrayForSavingInFile
(Matrix<? extends PArray> matrix) boolean
isCreatedBy
(Array array) Returns true if the passed array was created by this (or identical) memory model.static boolean
isCreatedReadOnly
(Array largeArray) Returns true if the passed large array was created byasArray(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.boolean
isElementTypeSupported
(Class<?> elementType) Returns true if this memory model can create arrays with this element type.static boolean
isLargeArray
(Array array) Returns true if the passed array was created by some instance of this memory model.static boolean
isTemporary
(Array largeArray) long
maxSupportedLength
(Class<?> elementType) Returnes maximal possible length of arrays with the specified element type supported by this memory model.Allocates a zero-filled resizable array with the specified element type and initial length.newEmptyArray
(Class<?> elementType) Allocates an empty resizable array with the specified element type and a little initial capacity.newEmptyArray
(Class<?> elementType, long initialCapacity) Allocates an empty resizable array with the specified element type and initial capacity.newLazyCopy
(Array array) See comments toMemoryModel.newLazyCopy(Array)
method.newUnresizableArray
(Class<?> elementType, long length) Allocates a zero-filled unresizable array with the specified element type and length.newUnresizableLazyCopy
(Array array) See comments toMemoryModel.newUnresizableLazyCopy(Array)
method.static void
setTemporary
(Array largeArray, boolean value) Changes temporary status, returned byisTemporary(Array)
method.toString()
Returns a brief string description of this memory model.Methods inherited from class net.algart.arrays.AbstractMemoryModel
newArray, newBitArray, newBitMatrix, newByteArray, newByteMatrix, newCharArray, newCharMatrix, newDoubleArray, newDoubleMatrix, newEmptyBitArray, newEmptyBitArray, newEmptyByteArray, newEmptyByteArray, newEmptyCharArray, newEmptyCharArray, newEmptyDoubleArray, newEmptyDoubleArray, newEmptyFloatArray, newEmptyFloatArray, newEmptyIntArray, newEmptyIntArray, newEmptyLongArray, newEmptyLongArray, newEmptyObjectArray, newEmptyObjectArray, newEmptyShortArray, newEmptyShortArray, newFloatArray, newFloatMatrix, newIntArray, newIntMatrix, newLazyCopy, newLongArray, newLongMatrix, newMatrix, newMatrix, newMatrix, newObjectArray, newObjectMatrix, newShortArray, newShortMatrix, newStructuredMatrix, newUnresizableArray, newUnresizableBitArray, newUnresizableByteArray, newUnresizableCharArray, newUnresizableDoubleArray, newUnresizableFloatArray, newUnresizableIntArray, newUnresizableLongArray, newUnresizableObjectArray, newUnresizableShortArray, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf, valueOf
-
Field Details
-
CONSTANT_PROPERTY_NAME
- See Also:
-
TILE_DIMENSIONS_PROPERTY_NAME
- See Also:
-
ALL_FILE
public static final long ALL_FILEThe special value for fileAreaSize argument inasArray
andasUpdatableArray
methods, that means the region from the specified position to the file end. Please note that this value is not applicable forasUpdatableArray
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
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 implementingMemoryModel
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:
- "DEFAULT" means
DefaultDataFileModel
, - "STANDARD_IO" means
StandardIODataFileModel
.
- Returns:
- default instance of this memory model.
- "DEFAULT" means
-
getInstance
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
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
Description copied from interface:MemoryModel
Allocates an empty resizable array with the specified element type and a little initial capacity. It is equivalent tonewEmptyArray(elementType, n)
, where n is some little value.Example of usage:
MutableFloatArray a = (MutableFloatArray)memoryModel.newEmptyArray(float.class);
- Specified by:
newEmptyArray
in interfaceMemoryModel
- Specified by:
newEmptyArray
in classAbstractMemoryModel
- Parameters:
elementType
- the type of array elements.- Returns:
- created AlgART array.
- See Also:
-
newEmptyArray
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
orCharArray
. 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 interfaceMemoryModel
- Specified by:
newEmptyArray
in classAbstractMemoryModel
- Parameters:
elementType
- the type of array elements.initialCapacity
- the initial capacity of the array.- Returns:
- created AlgART array.
- See Also:
-
newArray
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 interfaceMemoryModel
- Specified by:
newArray
in classAbstractMemoryModel
- Parameters:
elementType
- the type of array elements.initialLength
- the initial length and capacity of the array.- Returns:
- created AlgART array.
- See Also:
-
newUnresizableArray
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 (ornewUnresizableBitArray
,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 thelarge memory model
every resizable array is stored in the file consisting of integer number of blocks perDataFileModel.recommendedBankSize(true)
bytes.- Specified by:
newUnresizableArray
in interfaceMemoryModel
- Specified by:
newUnresizableArray
in classAbstractMemoryModel
- Parameters:
elementType
- the type of array elements.length
- the length and capacity of the array.- Returns:
- created unresizable AlgART array.
- See Also:
-
isElementTypeSupported
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 throwUnsupportedElementTypeException
. The result is not defined for void.class.- Specified by:
isElementTypeSupported
in interfaceMemoryModel
- Specified by:
isElementTypeSupported
in classAbstractMemoryModel
- 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 interfaceMemoryModel
- Specified by:
areAllPrimitiveElementTypesSupported
in classAbstractMemoryModel
- 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 interfaceMemoryModel
- Specified by:
areAllElementTypesSupported
in classAbstractMemoryModel
- Returns:
- true if this memory model supports element types.
- See Also:
-
maxSupportedLength
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 toMemoryModel.newEmptyArray(Class, long)
/MemoryModel.newArray(Class, long)
methods is greater than the result of this method, they will throwTooLargeArrayException
. 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 interfaceMemoryModel
- Specified by:
maxSupportedLength
in classAbstractMemoryModel
- Parameters:
elementType
- the type of array elements.- Returns:
- maximal possible length of arrays supported by this memory model.
-
isCreatedBy
Description copied from interface:MemoryModel
Returns true if the passed array was created by this (or identical) memory model.For
SimpleMemoryModel
andBufferMemoryModel
, "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 thedata file factory
.For
CombinedMemoryModel
, "identical" means that the memory model is also combined and was created with the same instance of thecombiner
.Returns false if the passed argument is null.
- Specified by:
isCreatedBy
in interfaceMemoryModel
- Specified by:
isCreatedBy
in classAbstractMemoryModel
- 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
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
Returns true is the passed array is temporary, that is if the correspondeddata file
storing all its elements will be automatically deleted when this AlgART array and all other arrays, sharing the same data (assubarrays
), 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 byasArray
orasUpdatableArray
methods. However, you may change this flag viasetTemporary(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
Changes temporary status, returned byisTemporary(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
orasUpdatableArray
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
Returns themodel
of thedata 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
Returns thepath
to thedata 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
orasUpdatableArray
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 (seeDataFileModel.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
Returns this memory model, cast to the specified generic type of the data file paths, or throws ClassCastException if the current typegetDataFileModel()
.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
Returns true if the passed large array was created byasArray(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 ofMemoryModel
, and only some its views, created with help ofArray.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 animmutable
AlgART array with specified element type, backed by the content of a region of thedata file
with specified name. To access the file, this method will convert the filePath toDataFile
instance bydataFileModel.getDataFile(filePath,byteOrder)
call, where dataFileModel is thecurrent 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 andALL_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 ofdata 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 toALL_FILE
.IndexOutOfBoundsException
- if the specified region exceeds the current file length.- See Also:
-
asUpdatableArray(Object, Class, long, long, boolean, ByteOrder)
asBitArray(Object, long, long, ByteOrder)
asCharArray(Object, long, long, ByteOrder)
asByteArray(Object, long, long, ByteOrder)
asShortArray(Object, long, long, ByteOrder)
asIntArray(Object, long, long, ByteOrder)
asLongArray(Object, long, long, ByteOrder)
asFloatArray(Object, long, long, ByteOrder)
asDoubleArray(Object, long, long, ByteOrder)
Arrays.copyBytesToArray(UpdatablePArray, byte[], ByteOrder)
Arrays.read(java.io.InputStream, UpdatablePArray, ByteOrder)
-
asUpdatableArray
public UpdatablePArray asUpdatableArray(P filePath, Class<?> elementType, long filePosition, long fileAreaSize, boolean truncate, ByteOrder byteOrder) throws IOException Returns anunresizable
AlgART array with specified element type, backed by the content of a region of thedata file
with specified name. To access the file, this method will convert the filePath toDataFile
instance bydataFileModel.getDataFile(filePath,byteOrder)
call, where dataFileModel is thecurrent 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
orArray.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 andALL_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 preferasArray
method.- Parameters:
filePath
- the name ofdata 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 toALL_FILE
.- See Also:
-
asArray(Object, Class, long, long, ByteOrder)
asUpdatableBitArray(Object, long, long, boolean, ByteOrder)
asUpdatableCharArray(Object, long, long, boolean, ByteOrder)
asUpdatableByteArray(Object, long, long, boolean, ByteOrder)
asUpdatableShortArray(Object, long, long, boolean, ByteOrder)
asUpdatableIntArray(Object, long, long, boolean, ByteOrder)
asUpdatableLongArray(Object, long, long, boolean, ByteOrder)
asUpdatableFloatArray(Object, long, long, boolean, ByteOrder)
asUpdatableDoubleArray(Object, long, long, boolean, ByteOrder)
Arrays.copyArrayToBytes(byte[], PArray, ByteOrder)
Arrays.write(java.io.OutputStream, PArray, ByteOrder)
-
asBitArray
public BitArray asBitArray(P filePath, long filePosition, long fileAreaSize, ByteOrder byteOrder) throws IOException Equivalent to (BitArray)asArray(filePath, boolean.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableBitArray)asUpdatableArray(filePath, boolean.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (CharArray)asArray(filePath, char.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableCharArray)asUpdatableArray(filePath, char.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 ofdata 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 toALL_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 ofdata 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 toALL_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 Equivalent to (ShortArray)asArray(filePath, short.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableShortArray)asUpdatableArray(filePath, short.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (IntArray)asArray(filePath, int.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableIntArray)asUpdatableArray(filePath, int.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (LongArray)asArray(filePath, long.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableLongArray)asUpdatableArray(filePath, long.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (FloatArray)asArray(filePath, float.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableFloatArray)asUpdatableArray(filePath, float.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (DoubleArray)asArray(filePath, double.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 Equivalent to (UpdatableDoubleArray)asUpdatableArray(filePath, double.class, filePosition, fileAreaSize, byteOrder)
.- Parameters:
filePath
- the name ofdata 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 toALL_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 -
asUpdatableMatrix
public Matrix<? extends UpdatablePArray> asUpdatableMatrix(P filePath, MatrixInfo matrixInfo) throws IOException, IllegalInfoSyntaxException -
getMatrixInfoForSavingInFile
public static MatrixInfo getMatrixInfoForSavingInFile(Matrix<? extends PArray> matrix, long dataOffset) -
getRawArrayForSavingInFile
-
newLazyCopy
See comments toMemoryModel.newLazyCopy(Array)
method.- Specified by:
newLazyCopy
in interfaceMemoryModel
- Overrides:
newLazyCopy
in classAbstractMemoryModel
- 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
See comments toMemoryModel.newUnresizableLazyCopy(Array)
method.- Specified by:
newUnresizableLazyCopy
in interfaceMemoryModel
- Overrides:
newUnresizableLazyCopy
in classAbstractMemoryModel
- 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, thenumber 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 ofmapped blocks
that were created by not finalized yet by this model. While this value is non-zero, thenumber 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
Returns a newly allocated copy of the set of alldata 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 itsDataFileModel.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
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.
-