Interface ArrayMemoryContext
- All Superinterfaces:
Context
- All Known Implementing Classes:
DefaultContext
The context informing the module, working with AlgART arrays
,
about the preferred memory model
.
Any module, that need to allocate AlgART arrays and that have no another information about desired memory model for new arrays (for example, passed directly as an algorithm parameter), should request this context to get the preferred memory model and use it. For example:
publicFloatArray
calculateSomeData(Context
context, some-other-arguments...) {ArrayMemoryContext
amc = context.as
(ArrayMemoryContext
.class); // - EMPTY context returns the default memory model (Arrays.SystemSettings.globalMemoryModel()
)MemoryModel
mm = amc.getMemoryModel()
;MutableFloatArray
result = mm.newEmptyFloatArray()
; . . . // filling result array by some algorithm return result; }
It allows an application to control how all AlgART arrays will be created by any modules,
"understanding" this context. For example, the application can require different algorithms
to create arrays by different instances of LargeMemoryModel
, that allocates
temporary files in different disk directories.
- Author:
- Daniel Alievsky
-
Method Summary
Modifier and TypeMethodDescriptionReturns thememory model
that should be used for creating any instances of AlgART arrays.getMemoryModel
(Class<?> elementType) Returns thememory model
that should be used for creating any instances of AlgART arrays with specified type of elements.getMemoryModel
(String settings) Returns thememory model
that should be used for creating any instances of AlgART arrays with some additional settings (recommendations).
-
Method Details
-
getMemoryModel
MemoryModel getMemoryModel()Returns thememory model
that should be used for creating any instances of AlgART arrays.- Returns:
- the desired memory model.
-
getMemoryModel
Returns thememory model
that should be used for creating any instances of AlgART arrays with specified type of elements. The typical implementation returns mm.isElementTypeSupported
(elementType) ? mm :SimpleMemoryModel.getInstance()
, where mm is the result ofgetMemoryModel()
method.- Parameters:
elementType
- the required element type.- Returns:
- the desired memory model.
- Throws:
NullPointerException
- if the argument is null.
-
getMemoryModel
Returns thememory model
that should be used for creating any instances of AlgART arrays with some additional settings (recommendations). Additional settings should be passed via settings argument (usually in JSON or analogous format); you can specify here some details about desired memory model. The context may consider your recommendations, specified in this argument, but also may ingnore them and return the same result as the simplegetMemoryModel()
method.If settings is "" (empty string), this methods must be equivalent to
getMemoryModel()
.- Parameters:
settings
- additional desires about the required memory model.- Returns:
- the desired memory model.
- Throws:
NullPointerException
- if the argument is null.
-