 | IJVMWrapperDirectNewDirectBufferT(T, Boolean, Boolean, Int32) Method |
Namespace: MASES.JCOBridge.C2JBridge.JVMInteropAssembly: C2JBridge (in C2JBridge.dll) Version: 2.6.9.260611-9a148513a79c26cdd7f1dde468f4f9e06ef3bc7e
SyntaxJCOBridgeDirectBuffer<T> NewDirectBuffer<T>(
T[] data,
bool useMemoryControlBlock = false,
bool arrangeCapacity = true,
int timeToLive = -1
)
where T : struct, new()
Function NewDirectBuffer(Of T As {Structure, New}) (
data As T(),
Optional useMemoryControlBlock As Boolean = false,
Optional arrangeCapacity As Boolean = true,
Optional timeToLive As Integer = -1
) As JCOBridgeDirectBuffer(Of T)Parameters
- data T
- The T array elements
- useMemoryControlBlock Boolean (Optional)
- NO MORE USED STARTING FROM VERSION 2.6.9 - Appends to the end of the data a memory block used to control and arbitrate 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 the 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 of 2 at origin. If useMemoryControlBlock is and there is no space left between capacity and limit,
an extra resize is executed without considering 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 internal copy 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
JCOBridgeDirectBufferTA new instance of
JCOBridgeDirectBufferT holding an internal copy of
data shared with the
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html
Exceptions
Remarks
Starting from version 2.6.9, the content of
data is no longer pinned in memory but copied into an internal buffer managed by the subsystem.
Prior to version 2.6.9, the memory had to be pinned for the entire duration of the JVM usage to prevent access violations; the introduction of the internal copy removes this constraint,
allowing
data to have an arbitrary lifetime without impacting the correctness of the operation.
The internal copy remains available until the JVM reference of the newly created
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html is garbage collected.
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 internal copy is no longer 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.
High-rate scenarios: for activities with a high invocation rate, consider using RentT(Int64) to obtain a pooled JCOBridgeSharedBufferStreamT,
fill it using Stream-based APIs, and then pass the populated instance to NewDirectBufferT(JCOBridgeSharedBufferStreamT).
That overload automatically manages the lifecycle of the JCOBridgeSharedBufferStreamT by returning it to the pool once the JVM Garbage Collector retires the associated
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html, avoiding repeated allocation and copy overhead.
See Also