java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.CharArray
CharArray relies on preview features of the Java platform:
CharArrayrefers to one or more preview APIs:MemorySegment.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This class represents an array of characters stored in native memory.
The char data is stored in a
MemorySegmentPREVIEW, which represents a contiguous region of off-heap memory.
The class also encapsulates methods for setting and getting char values,
for initializing the char array, and for converting the array to and from different representations.-
Field Summary
Fields inherited from class uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
ARRAY_HEADER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values of theCharArrayinstance to , the default char value.static CharArraystatic CharArrayfromArray(char[] values) Creates a new instance of theCharArrayclass from an on-heap char array.static CharArrayfromCharBuffer(CharBuffer buffer) Creates a new instance of theCharArrayclass from aCharBuffer.static CharArrayfromElements(char... values) Creates a new instance of theCharArrayclass from a set of char values.static CharArrayfromSegment(MemorySegmentPREVIEW segment) static CharArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theCharArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.charget(int index) Gets the char value stored at the specified index of theCharArrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theCharArrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theCharArrayinstance, occupies.intgetSize()Returns the number of char elements stored in theCharArrayinstance.voidinit(char value) Initializes all the elements of theCharArrayinstance with a specified value.static voidinitialize(CharArray array, char value) Factory method to initialize aCharArray.voidset(int index, char value) Sets the char value at a specified index of theCharArrayinstance.slice(int offset, int length) char[]Converts the char data from off-heap to on-heap, by copying the values of aCharArrayinstance into a new on-heap array.
-
Constructor Details
-
CharArray
public CharArray(int numberOfElements) Constructs a new instance of theCharArraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
CharArray
Constructs a newCharArrayinstance by concatenating the contents of the given array ofCharArrayinstances.- Parameters:
arrays- An array ofCharArrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theCharArrayclass from an on-heap char array.- Parameters:
values- The on-heap char array to create the instance from.- Returns:
- A new
CharArrayinstance, initialized with values of the on-heap char array.
-
fromElements
Creates a new instance of theCharArrayclass from a set of char values.- Parameters:
values- The char values to initialize the array with.- Returns:
- A new
CharArrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap char data.- Returns:
- A new
CharArrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theCharArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap char *header* and *data*.- Returns:
- A new
CharArrayinstance that wraps the given segment.
-
fromCharBuffer
Creates a new instance of theCharArrayclass from aCharBuffer.- Parameters:
buffer- TheCharBuffercontaining the float data.- Returns:
- A new
CharArrayinstance, initialized with the buffer data.
-
clear
public void clear()Sets all the values of theCharArrayinstance to , the default char value.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
toHeapArray
public char[] toHeapArray()Converts the char data from off-heap to on-heap, by copying the values of aCharArrayinstance into a new on-heap array.- Returns:
- A new on-heap char array, initialized with the values stored in the
CharArrayinstance.
-
set
public void set(int index, char value) Sets the char value at a specified index of theCharArrayinstance.- Parameters:
index- The index at which to set the char value.value- The char value to store at the specified index.
-
get
public char get(int index) Gets the char value stored at the specified index of theCharArrayinstance.- Parameters:
index- The index of which to retrieve the char value.- Returns:
-
init
public void init(char value) Initializes all the elements of theCharArrayinstance with a specified value.- Parameters:
value- The char value to initialize theByteArrayinstance with.
-
getSize
public int getSize()Returns the number of char elements stored in theCharArrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theCharArrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theCharArrayinstance.
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theCharArrayinstance, occupies.- Specified by:
getNumBytesOfSegmentWithHeaderin classTornadoNativeArray- Returns:
- The total number of bytes of the
MemorySegmentPREVIEW.
-
getNumBytesOfSegment
public long getNumBytesOfSegment()Returns the number of bytes of theMemorySegmentPREVIEW that is associated with theCharArrayinstance, excluding the header bytes.- Specified by:
getNumBytesOfSegmentin classTornadoNativeArray- Returns:
- The number of bytes of the raw data in the
MemorySegmentPREVIEW.
-
initialize
Factory method to initialize aCharArray. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The float value to initialize theCharArrayinstance with.
-
concat
-
slice
- Parameters:
offset- The starting index from which to begin the slice, inclusive.length- The number of elements to include in the slice.- Returns:
- A new
CharArrayinstance representing the specified slice of the original array. - Throws:
IllegalArgumentException- if the specified slice is out of the bounds of the original array.
-
CharArraywhen preview features are enabled.