Click or drag to resize

IJVMWrapperDirectNewDirectBuffer(MemoryStream, Boolean, EventHandlerMemoryStream, Int32) Method

Creates a new https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html in the JVM which shares the stream. The method helps to avoid too many array copies from CLR to JVM

Namespace: MASES.JCOBridge.C2JBridge.JVMInterop
Assembly: C2JBridge (in C2JBridge.dll) Version: 2.5.17.240622-f0da58d62b7e98f73f32432917df8eb1a5f062a3
Syntax
JCOBridgeDirectBuffer<byte> NewDirectBuffer(
	MemoryStream stream,
	bool useMemoryControlBlock = true,
	EventHandler<MemoryStream> disposeEvent = null,
	int timeToLive = -1
)

Parameters

stream  MemoryStream
The non disposed MemoryStream to be used directly within the JVM from a https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html, see remarks
useMemoryControlBlock  Boolean  (Optional)
Appends to the end of the stream a memory block will be used to controls and arbitrates memory between CLR and JVM
disposeEvent  EventHandlerMemoryStream  (Optional)
An optional EventHandlerTEventArgs can be used to be informed when the stream can be safely disposed (the dispose action shall be in the user code), if the underlying system will automatically dispose the MemoryStream.
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.

Return Value

JCOBridgeDirectBufferByte
A new instance of JCOBridgeDirectBufferT holding the memory of stream shared with the https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html
Remarks
The memory associated to stream 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 The MemoryStream cannot be disposed otherwise the underlying system is not able to access the memory. The MemoryStream can be written, or read, and changes are visible to both CLR and JVM, however, if the MemoryStream grows, the underlying system cannot resize too and capacity still remains the one when NewDirectBuffer(MemoryStream, Boolean, EventHandlerMemoryStream, Int32) was invoked the first time.
See Also