久久久久久久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| 欧美极品视频 | 欧美成年人网站 | 成人激情视频在线观看 | 中文字幕日韩欧美一区二区三区 | 在线观看久草 | 成人3d动漫一区二区三区91 | 欧美11一13sex性hd| 久久久免费毛片 | 午夜成人免费视频 | 亚州午夜精品 | 亚洲97 | 久色一区| 亚洲成人福利视频 | 福利久久| 精品在线99 | 欧美日一区二区 | 91色在线视频 | 中文字幕亚洲精品在线观看 | h视频免费在线观看 | 国产精品99久久久久久宅男 | 91视频播放| 台湾a级理论片在线观看 | 日韩一二三区视频 | 玖玖国产 | 99爱国产 | 亚洲天堂一区 | 久久大陆 | 国产中文字幕av | 99热在线免费 | 国产99视频精品免视看9 | 亚洲成av人影片在线观看 | 理论片免费在线观看 |