java 内存复制 DirectBuffer

发布于 2024-11-10 16:46:49 字数 128 浏览 5 评论 0原文

您好,我正在使用 Java 中的直接缓冲区,并且我需要对它们进行快速内存复制。在 C 中,有 memcpy 命令,在 Java 数组中,有 Arrays.copyOf。但是没有办法使用数组代替直接缓冲区,因为我需要将它们传输到 OpenGL。

Hi I am working with direct buffers in Java, and I need to have a fast memcopy on them. In C there is the memcpy command, and on Java Arrays I have Arrays.copyOf. But there is no way of using Arrays instead of direct buffers, because I need to transfer those to OpenGL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天荒地未老 2024-11-17 16:46:49

如果您的意思是“直接”ByteBuffer,则有一个 put 方法接受其他 ByteBuffer 实例,以便您可以复制。

If you mean "direct" ByteBuffers, there's a put method which accepts other ByteBuffer instances so you can copy around.

姐不稀罕 2024-11-17 16:46:49

您可以仅将 put() 与 byte[] 或 ByteBuffer 一起使用,这将在 Sun/Oracle JDK 中使用本机调用 memcpy。

对于直接和堆字节缓冲区,put() 使用 Bits.copyFromArray()Unsafe.copyMemory() 方法。

You can just use put() with either a byte[] or a ByteBuffer, this will use a native call memcpy under neither in the Sun/Oracle JDK.

For direct and heap byte buffers put() uses the Bits.copyFromArray() and Unsafe.copyMemory() methods.

七七 2024-11-17 16:46:49

检查 System.arrayCopy 这是在java中复制部分数组的最快方法

check System.arrayCopy it's the fastest way to copy part of an array in java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文