Table of Contents

Class JCOBridgeDirectBuffer<T>

Namespace
MASES.JCOBridge.C2JBridge
Assembly
C2JBridge.dll

A class to manage shared memory between .NET and JVM using a memory region created in the CLR and shared with the JVM using https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html

public class JCOBridgeDirectBuffer<T> : IEnumerable<T>, IEnumerable, IDisposable

Type Parameters

T

The Type to be used: it can be any byte, short, int, long, float, double or a type defined as a struct

Inheritance
JCOBridgeDirectBuffer<T>
Implements
Inherited Members
Extension Methods

Properties

this[long]

Get or set the memory of the shared buffer at index

public T this[long index] { get; set; }

Parameters

index long

The memory index to be set or get

Property Value

T

The value of the shared memory at index

JavaObject

public IJavaObject JavaObject { get; }

Property Value

IJavaObject

Methods

As<TNew>()

Returns a new instance of JCOBridgeDirectBuffer<T>

public JCOBridgeDirectBuffer<TNew> As<TNew>()

Returns

JCOBridgeDirectBuffer<TNew>

The new instance of JCOBridgeDirectBuffer<T>

Type Parameters

TNew

The new Type to use

CopyTo(IntPtr, long, long, long)

Fills the destination with the copy of the memory this JCOBridgeDirectBuffer<T> instance is holding

public long CopyTo(IntPtr destination, long destinationSize, long startPosition, long length)

Parameters

destination IntPtr

The IntPtr describing the memory pointer data shall be written with the content of the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html

destinationSize long

The available memory size of destination

startPosition long

The position within the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html where the copy shall start

length long

The number of bytes to be copied from the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html into destination

Returns

long

The bytes copied

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

FillWithArray<TArray>(TArray[], long)

Copies the content of array into memory managed from this JCOBridgeDirectBuffer<T> instance

public void FillWithArray<TArray>(TArray[] array, long destinationStartIndex = 0)

Parameters

array TArray[]

The TArray array to be copied

destinationStartIndex long

The start index on destination buffer where to copy

Type Parameters

TArray

The Type to be used: it can be any byte, short, int, long, float, double or a type defined as a struct

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator that can be used to iterate through the collection.

GetValue(int)

Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.

public T GetValue(int index)

Parameters

index int

A 32-bit integer that represents the position of the Array element to get.

Returns

T

The value at the specified position in the one-dimensional Array.

Exceptions

ArgumentException

The current Array does not have exactly one dimension.

IndexOutOfRangeException

index is outside the range of valid indexes for the current Array.

GetValue(long)

Gets the value at the specified position in the one-dimensional Array. The index is specified as a 64-bit integer.

public T GetValue(long index)

Parameters

index long

A 64-bit integer that represents the position of the Array element to get.

Returns

T

The value at the specified position in the one-dimensional Array.

Exceptions

ArgumentException

The current Array does not have exactly one dimension.

ArgumentOutOfRangeException

index is outside the range of valid indexes for the current Array.

Initialize()

Initializes every element of the value-type Array by calling the default constructor of the value type.

public void Initialize()

SetValue(T, int)

Sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.

public void SetValue(T value, int index)

Parameters

value T

The new value for the specified element.

index int

A 32-bit integer that represents the position of the Array element to set.

Exceptions

ArgumentException

The current Array does not have exactly one dimension.

InvalidCastException

value cannot be cast to the element type of the current Array.

IndexOutOfRangeException

index is outside the range of valid indexes for the current Array.

SetValue(T, long)

Sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 64-bit integer.

public void SetValue(T value, long index)

Parameters

value T

The new value for the specified element.

index long

A 64-bit integer that represents the position of the Array element to set.

Exceptions

ArgumentException

The current Array does not have exactly one dimension.

InvalidCastException

value cannot be cast to the element type of the current Array.

ArgumentOutOfRangeException

index is outside the range of valid indexes for the current Array.

ToArray<TArray>()

Returns a TArray array which is the copy of the memory this JCOBridgeDirectBuffer<T> instance is holding

public TArray[] ToArray<TArray>()

Returns

TArray[]

A TArray array which is the copy of the memory this instance is holding

Type Parameters

TArray

The Type to be used: it can be any byte, short, int, long, float, double or a type defined as a struct

ToArray<TArray>(ref TArray[], bool)

Fills the array with the copy of the memory this JCOBridgeDirectBuffer<T> instance is holding

public void ToArray<TArray>(ref TArray[] array, bool resizeToFill = true)

Parameters

array TArray[]

The array to be filled with the content of the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html

resizeToFill bool

Resize array to contain all data available in the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html

Type Parameters

TArray

The Type to be used: it can be any byte, short, int, long, float, double or a type defined as a struct

ToStream()

Converts this instance to a Stream can be used to manage directly the underlying memory without make intermediate array copy

public Stream ToStream()

Returns

Stream

A new instance of Stream

Operators

implicit operator Stream(JCOBridgeDirectBuffer<T>)

Converts this instance to a Stream can be used to manage directly the underlying memory without make intermediate array copy

public static implicit operator Stream(JCOBridgeDirectBuffer<T> t)

Parameters

t JCOBridgeDirectBuffer<T>

The JCOBridgeDirectBuffer<T> to be converted

Returns

Stream

A Stream

implicit operator T[](JCOBridgeDirectBuffer<T>)

Returns a T array which is the copy of the memory the t instance is holding

public static implicit operator T[](JCOBridgeDirectBuffer<T> t)

Parameters

t JCOBridgeDirectBuffer<T>

The JCOBridgeDirectBuffer<T> to be converted

Returns

T[]

An array of T