如何固定Java中的字节数组? [英] How can I pin a byte array in Java?

查看:85
本文介绍了如何固定Java中的字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以固定Java中的字节数组,从而使其永远不会移动/压缩?

Is there a way to pin a byte array in java, so it never gets moved/compacted?

我正在开发一个应用程序,该应用程序打算在运行时具有零个GC,并且我想使用固定到内存映射区域的原始字节数组.有什么方法可以做到这一点或破解我的方法吗?

I am working on an application which is intended to have zero GCs during runtime, and I want to use primitive byte arrays that are pinned to a memory mapped area. Is there any way to do this or hack my way to it?

推荐答案

您可以使用ByteBuffer/allocateDirect()这将创建一个字节缓冲区,该缓冲区位于"c"空间中,并且不使用堆,因此不会可以移动并可以有效地用于JNI调用.

You can use a ByteBuffer/allocateDirect() This creates a byte buffer which is in the "c" space and doesn't use heap so it won't get moved and can be use efficiently with JNI calls.

这篇关于如何固定Java中的字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆