Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  132] [ 7]  / answers: 1 / hits: 20196  / 11 Years ago, tue, september 3, 2013, 12:00:00

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.


More From » arrays

 Answers
9
var buff = new ArrayBuffer(32);
buff[31] = 43;
var newBuff = new ArrayBuffer(buff.byteLength*2);

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

buff = newBuff;


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.


[#75918] Tuesday, September 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
declanm

Total Points: 614
Total Questions: 105
Total Answers: 97

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;