When you initialize an ArrayBuffer with maxByteLength to make it resizeable, are maxByteLength bytes reserved in memory up front so that the ArrayBuffer can grow in contiguous memory space?
Or is a new memory space reserved when you resize it? If so, are the bytes from the original ArrayBuffer copied over, or does the ArrayBuffer maintain references to multiple non-contiguous regions?
Code example to explain the situation I'm talking about:
const a = new ArrayBuffer(4, { maxByteLength: 8 });
new Uint32Array(a)[0] = 1024;
/* Will the ArrayBuffer grow within the initially
allocated memory region here,
will it reserve 4 more bytes somewhere else,
or will it reserve 8 bytes somewhere else and copy
over the existing data? */
a.resize(8);
You can assign a new size to a resizable ArrayBuffer with a resize() call. New bytes are initialized to 0.