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

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

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

問題描述

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

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

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

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.

問題:

  • 與任何其他類型的集合或簡單的浮點數(shù)組相比,這種類型的類(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 轉(zhuǎn)換為 FloatBuffer 之前創(chuàng)建它的想法是什么?

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

推薦答案

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

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).

例如,如果您正在執(zhí)行大量 OpenGL 渲染調(diào)用,這一點非常重要.

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

首先創(chuàng)建一個 ByteBuffer 的原因是您想使用 allocateDirect 調(diào)用來創(chuàng)建一個 direct 字節(jié)緩沖區(qū),這得益于加速操作.然后,您可以從中創(chuàng)建一個共享相同內(nèi)存的 FloatBuffer.由于某種原因,F(xiàn)loatBuffer 本身沒有 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.

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
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 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲综合在线视频 | 久久精品国产99国产精品亚洲 | 国产婷婷精品av在线 | 精品久久伊人 | 国产激情一区二区三区 | 婷婷色综合| 欧美1页 | 国产精品欧美一区二区 | 欧美寡妇偷汉性猛交 | 久久国产精品72免费观看 | 精品美女久久久 | 国产一区视频在线 | www.久| 日韩精品视频在线观看一区二区三区 | a亚洲精品 | 欧美一级三级在线观看 | 久热精品在线观看视频 | 人人人艹| 久热伊人 | 成人精品一区二区三区 | 四色永久 | 亚洲三级在线观看 | 91av小视频 | 国产精品美女www爽爽爽视频 | 日韩伦理电影免费在线观看 | 精品欧美一区二区三区久久久 | 亚洲成人午夜在线 | 国产成人精品一区二区三区视频 | 久久综合一区二区 | 一级黄在线观看 | 婷婷五月色综合香五月 | 欧美a视频 | 国产精品日韩欧美一区二区三区 | 91精品一区二区三区久久久久久 | 欧美高清视频一区 | 国产精品三级 | 三级欧美| 久久久www | 黄色欧美大片 | 日韩精品极品视频在线观看免费 | 91精品国产欧美一区二区 |