| IJVMWrapperDirectNewDirectBuffer(MemoryStream, Boolean, EventHandlerMemoryStream, Int32) Method |
Namespace: MASES.JCOBridge.C2JBridge.JVMInteropAssembly: C2JBridge (in C2JBridge.dll) Version: 2.5.21.241219-a6a144ea07c497c3a9a1be842408e852afb458be
Syntax JCOBridgeDirectBuffer<byte> NewDirectBuffer(
MemoryStream stream,
bool useMemoryControlBlock = true,
EventHandler<MemoryStream> disposeEvent = null,
int timeToLive = -1
)
Function NewDirectBuffer (
stream As MemoryStream,
Optional useMemoryControlBlock As Boolean = true,
Optional disposeEvent As EventHandler(Of MemoryStream) = Nothing,
Optional timeToLive As Integer = -1
) As JCOBridgeDirectBuffer(Of Byte)
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
JCOBridgeDirectBufferByteA new instance of
JCOBridgeDirectBufferT holding the memory of
stream shared with the
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.htmlRemarks
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