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.
Advertisement
Answer
JavaScript
x
10
10
1
var buff = new ArrayBuffer(32);
2
buff[31] = 43;
3
var newBuff = new ArrayBuffer(buff.byteLength*2);
4
5
for (var i=0;i<buff.byteLength;i++){
6
newBuff[i] = buff[i];
7
}
8
9
buff = newBuff;
10
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.