久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么使用 FloatBuffer 而不是 float[]?

Why FloatBuffer instead of float[]?(為什么使用 FloatBuffer 而不是 float[]?)
本文介紹了為什么使用 FloatBuffer 而不是 float[]?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我已經在我的 Android 代碼中使用 FloatBuffers 有一段時間了(從一些 opengles 教程中復制了它),但我無法準確理解這個構造是什么以及為什么需要它.

I've been using FloatBuffers in my Android code for a while (copied it from some opengles tutorial), but I cannot understand exactly what this construct is and why it is needed.

例如,我在很多人的代碼和 android 教程中看到的這段代碼(或類似代碼):

For example this code (or similar) I see in many many peoples' code and android tutorials:

float[] vertices = ...some array...

ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4); 
vbb.order(ByteOrder.nativeOrder());    // use the device hardware's native byte order
FloatBuffer fb = vbb.asFloatBuffer();  // create a floating point buffer from the ByteBuffer
fb.put(vertices);    // add the coordinates to the FloatBuffer
fb.position(0);      // set the buffer to read the first coordinate

這似乎非常冗長和混亂,據我所知,這只是一個花哨的浮點數組的包裝.

This seems awfully verbose and messy for something which as far as I can tell is just a fancy wrapper around of an array of floats.

問題:

  • 與任何其他類型的集合或簡單的浮點數組相比,這種類型的類(ByteBuffer、FloatBuffer)的理由是什么?

  • What is the justification for this type of class (ByteBuffer, FloatBuffer), as opposed to any other kind of collection or simple array of floats?

在將 ByteBuffer 轉換為 FloatBuffer 之前創建它的想法是什么?

What's the idea behind creating a ByteBuffer before converting it into a FloatBuffer?

推薦答案

主要原因是性能:ByteBuffers 和其他 NIO 類在與本機代碼交互時啟用加速操作(通常是通過避免將數據復制到臨時緩沖區).

The main reason is performance: ByteBuffers and the other NIO classes enable accelerated operations when interfacing with native code (typically by avoiding the need to copy data into a temporary buffer).

例如,如果您正在執行大量 OpenGL 渲染調用,這一點非常重要.

This is pretty important if you are doing a lot of OpenGL rendering calls for example.

首先創建一個 ByteBuffer 的原因是您想使用 allocateDirect 調用來創建一個 direct 字節緩沖區,這得益于加速操作.然后,您可以從中創建一個共享相同內存的 FloatBuffer.由于某種原因,FloatBuffer 本身沒有 allocateDirect 方法,這就是您必須通過 ByteBuffer 的原因.

The reason for creating a ByteBuffer first is that you want to use the allocateDirect call to create a direct byte buffer, which benefits from the accelerated operations. You then create a FloatBuffer from this that shares the same memory. The FloatBuffer doesn't itself have an allocateDirect method for some reason, which is why you have to go via ByteBuffer.

這篇關于為什么使用 FloatBuffer 而不是 float[]?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美日韩在线观看视频 | 人人艹人人 | 国产伦精品一区二区三区视频我 | 亚洲第一免费视频 | 精品在线观看视频 | 一区二区水蜜桃 | 日韩黄色在线视频 | 国产视频在线看 | 欧美国产在线视频 | 亚洲亚洲人成综合网络 | 国产一区二区在线看 | xxxx亚洲| 依人久久 | 午夜成人影片 | 日韩欧美精品 | 五月婷婷激情 | 国产成人精品网站 | 亚洲精品18在线观看 | 欧美激情视频一区二区三区 | 久久一区二区视频 | 午夜伦理福利 | 国产三级在线观看视频 | 日本黄色一级视频 | 五月婷婷 | 国产精品毛片久久久久久久 | 日日日操操操 | 国产一区二区在线播放 | 亚洲综合伊人 | 国产美女毛片 | 亚洲高清免费 | 九月丁香婷婷 | 精品视频999 | 日本免费一级 | 国产精品久久久999 成人在线国产 | 国产又色又爽又黄又免费 | 色香蕉网 | 国产免费黄色片 | 欧美在线视频一区二区 | 欧美久久久 | 天天色影院 | 深夜视频在线观看 |