Skip to content

Commit

Permalink
keep re estructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Mar 19, 2024
1 parent bf15995 commit 6ef4a95
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.Closeable;
import java.io.File;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.UUID;

import com.sun.jna.Pointer;
Expand Down Expand Up @@ -139,6 +138,55 @@ SharedMemoryArray create(long[] shape, T datatype) {
else return new SharedMemoryArrayMacOS(size * DecodeNumpy.DATA_TYPES_MAP.get(strDType), strDType, shape);
}

/**
* This method creates a segment on the Shared Memory region of the computer with the size
* needed to store an image of the wanted characteristics.
* It is useful to allocate in advance the space that a certain {@link RandomAccessibleInterval}
* will need. The image can then reference this shared memory region.
* An instance of {@link SharedMemoryArray} is created that helps managing the shared memory data.
*
* The amount of space reserved will depend on the shape provided and the datatype.
*
* @param <T>
* possible ImgLib2 data types of the wanted {@link RandomAccessibleInterval}
* @param name
* name of the shared memory region that has been created
* @param shape
* shape of an ndimensional array that could be stored in the shared memory region
* @param datatype
* datatype of the data that is going to be stored in the region
* @return a {@link SharedMemoryArray} instance that helps handling the data written to the shared memory region
*/
static <T extends RealType<T> & NativeType<T>>
SharedMemoryArray readOrCreate(String name, int size) {
if (PlatformDetection.isWindows()) return new SharedMemoryArrayWin(name, size, null, null);
else if (PlatformDetection.isLinux()) return new SharedMemoryArrayLinux(name, size, null, null);
else return new SharedMemoryArrayMacOS(name, size, null, null);
}

/**
* This method creates a segment on the Shared Memory region of the computer with the size
* needed to store an image of the wanted characteristics.
* It is useful to allocate in advance the space that a certain {@link RandomAccessibleInterval}
* will need. The image can then reference this shared memory region.
* An instance of {@link SharedMemoryArray} is created that helps managing the shared memory data.
*
* The amount of space reserved will depend on the shape provided and the datatype.
*
* @param <T>
* possible ImgLib2 data types of the wanted {@link RandomAccessibleInterval}
* @param shape
* shape of an ndimensional array that could be stored in the shared memory region
* @param datatype
* datatype of the data that is going to be stored in the region
* @return a {@link SharedMemoryArray} instance that helps handling the data written to the shared memory region
*/
static SharedMemoryArray create(int size) {
if (PlatformDetection.isWindows()) return new SharedMemoryArrayWin(size, null, null);
else if (PlatformDetection.isLinux()) return new SharedMemoryArrayLinux(size, null, null);
else return new SharedMemoryArrayMacOS(size, null, null);
}

/**
* This method copies the data from a {@link RandomAccessibleInterval} into a shared memory region
* to be able to shared it with other processes.
Expand Down

0 comments on commit 6ef4a95

Please sign in to comment.