Maybe it's late, or maybe it's the sake, but I just read the docs for ArrayBuffer and can't think of a single thing it would be really useful for.

也许它已经很晚了,或者也许是为了这个缘故,但我只是阅读了ArrayBuffer的文档而无法想到它会对它有用的一件事。

Can someone enlighten me?

有人可以开导我吗?

Are there any uses anyone can think of that don't involve images?

是否有任何人可以想到的不涉及图像的用途?

1 个解决方案

#1


35

Basically ArrayBuffer is used to keep binary data. It can be the binary data of an image for example.

基本上ArrayBuffer用于保存二进制数据。例如,它可以是图像的二进制数据。

In other languages buffers are proved very useful. Yes, of-course it is little difficult to understand/use than other data types.

在其他语言中,缓冲区被证明非常有用。是的,当然,理解/使用它比其他数据类型有点困难。

ArrayBuffer can be used to get data of jpg image (RGB bytes) and produce a png out of it by adding alpha byte (i.e. RGBA).

ArrayBuffer可用于获取jpg图像(RGB字节)的数据,并通过添加alpha字节(即RGBA)从中产生png。

Mozilla site has given a small use of ArrayBuffer here

Mozilla网站在这里给出了一点使用ArrayBuffer

Scroll down to find the section Working with complex data structures

向下滚动以查找使用复杂数据结构的部分

I have copied the text from there:

我从那里复制了文字:

Working with complex data structures

使用复杂的数据结构

By combining a single buffer with multiple views of different types, starting at different offsets into the buffer, you can interact with data objects containing multiple data types. This lets you, for example, interact with complex data structures from WebGL, data files, or C structures you need to use while using js-ctypes.

通过将单个缓冲区与不同类型的多个视图组合,从不同的偏移量开始到缓冲区,您可以与包含多种数据类型的数据对象进行交互。例如,这使您可以在使用js-ctypes时与WebGL,数据文件或C结构中的复杂数据结构进行交互。

Consider this C structure:

考虑这个C结构:

struct someStruct {  
  unsigned long id;  
  char username[16];  
  float amountDue;  
};  

You can access a buffer containing data in this format like this:

您可以访问包含以下格式的数据的缓冲区,如下所示:

var buffer = new ArrayBuffer(24);  

// ... read the data into the buffer ...  

var idView = new Uint32Array(buffer, 0, 1);  
var usernameView = new Uint8Array(buffer, 4, 16);  
var amountDueView = new Float32Array(buffer, 20, 1);  

Then you can access, for example, the amount due with amountDueView[0].

然后,您可以使用amountDueView [0]访问应付金额。

更多相关文章

  1. 基于缓冲区数据创建文件
  2. Python基本数据结构
  3. python尝试自定义数据结构不知道怎么下手
  4. 《数据结构与算法Python语言描述》裘宗燕 笔记 第五章 栈和队列
  5. Linux内核数据结构之链表
  6. java数据结构--链表
  7. 数据结构:关于重建二叉树的三种思路
  8. “树”不倒,人不散—数据结构的核心
  9. Java nio 学习笔记(一) Buffer(缓冲区)与Channel(通道)的相关知识

随机推荐

  1. 读完《MyBatis技术内幕》,聊几句感触
  2. JVM 家族
  3. 从对象生命周期的经验统计到垃圾回收算法
  4. Nacos集群模式部署
  5. 穿插一个 MyBatis 分页插件 PageHelper
  6. CCNP(ISCW)实验:用命令行配置GRE OVER IPS
  7. Java 类的静态变量存放在哪块内存中?
  8. 那些垃圾收集器,及特点
  9. 解 23 道 MyBatis 题(2)
  10. HotSpot VM 中对象的内存分析