don kaka don kaka - 1 year ago 179
Javascript Question

Resize ArrayBuffer

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.

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download