本文介绍了调整ArrayBuffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想创建一个arraybuffer,我写的: VAR的buff =新ArrayBuffer(大小)

但怎么可能来调整现有的缓冲区?我的意思是,在缓冲区末尾添加一些更多的字节。


解决方案

  VAR BUF =新ArrayBuffer(32);
BUF [31] = 43;
VAR的buff =新ArrayBuffer(buf.byteLength * 2);对于(VAR I = 0; I< buf.byteLength;我++){
    BUFF [I] = BUF [I]
}BUF = BUFF;

我用C做了++这样。只是做了较大的阵列,并在复制的内容,然后返回更大的数组并将其设置为原件。

If I want to create an arraybuffer, I write: var buff = new ArrayBuffer(size)

But how is it possible to resize an existing buffer? I mean, adding some more bytes at the end of the buffer.

解决方案
var buf = new ArrayBuffer(32);
buf[31] = 43;
var buff = new ArrayBuffer(buf.byteLength*2);

for (var i=0;i<buf.byteLength;i++){
    buff[i] = buf[i];
}

buf = buff;

I've done it in C++ like this. Just made a bigger array and copy the contents over and then return the larger array and set it as the original.

这篇关于调整ArrayBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:38