Click or drag to resize

IJVMWrapperDirectNewDirectBufferT(T, Boolean, Boolean, Int32) Method

Creates a new https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html in the JVM which belongs to data. If this method is used in conjunction with arrangeCapacity and/or useMemoryControlBlock set to , better performances are obtained from NewDirectBuffer(MemoryStream, Boolean, EventHandlerMemoryStream, Int32) becuase MemoryStream automatically manages its capacity and, in general, will be the memory space available for control memory block needed from useMemoryControlBlock set to

Namespace: MASES.JCOBridge.C2JBridge.JVMInterop
Assembly: C2JBridge (in C2JBridge.dll) Version: 2.5.13.240514-86ea0fe57add44a0d4dc719a1a99f3379a320f2e
Syntax
JCOBridgeDirectBuffer<T> NewDirectBuffer<T>(
	T[] data,
	bool useMemoryControlBlock = true,
	bool arrangeCapacity = true,
	int timeToLive = -1
)

Parameters

data  T
The T array elements
useMemoryControlBlock  Boolean  (Optional)
Appends to the end of the data a memory block will be used to controls and arbitrates memory between CLR and JVM
arrangeCapacity  Boolean  (Optional)
If the T array in data will be resized to the next power of 2, so capacity will be memory aligned and the limit of https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html will be current size of data. However if the T array in data needs a resize, the memory will be copied during the capacity arrangement, if arrangeCapacity is a good approach is to allocate an array which is a power 2 at origin. If useMemoryControlBlock is and there is no space left, between capacity and limit, an extra resize is executed without consider the value of arrangeCapacity
timeToLive  Int32  (Optional)
The time to live, expressed in milliseconds, the underlying memory shall remain available; if the time to live expires the pinned memory is retired leaving potentially the JVM under the possibility of an access violation.

Type Parameters

T
The native type of the resulting JCOBridgeDirectBufferT

Return Value

JCOBridgeDirectBufferT
A new instance of JCOBridgeDirectBufferT holding the memory of data shared with the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html
Remarks
The memory associated to data will be pinned until the JVM reference of the newly created https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html is garbage collected to avoid access violation within the JVM. Under heavy pressure the memory footprint can raise up and generate an OutOfMemoryException, use the functionality with caution or take into account the timeToLive option which can help to recover the memory in advance before the Garbage Collector of the JVM retires the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html If the user of JCOBridgeDirectBufferT is pretty sure that the pinned memory is no more needed from the JVM, e.g. the invoked method does not queue the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html and its lifetime ends when the method returns, invoke Dispose to immediately release unmanaged resources and free the memory
See Also