Interface ArrayMemoryContext

All Superinterfaces:
Context
All Known Implementing Classes:
DefaultContext

public interface ArrayMemoryContext extends Context

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:

 public FloatArray 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 Details

    • getMemoryModel

      MemoryModel getMemoryModel()
      Returns the memory model that should be used for creating any instances of AlgART arrays.
      Returns:
      the desired memory model.
    • getMemoryModel

      MemoryModel getMemoryModel(Class<?> elementType)
      Returns the memory 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 of getMemoryModel() method.
      Parameters:
      elementType - the required element type.
      Returns:
      the desired memory model.
      Throws:
      NullPointerException - if the argument is null.
    • getMemoryModel

      MemoryModel getMemoryModel(String settings)
      Returns the memory 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 simple getMemoryModel() 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.