- Open your command-line application, and navigate to your workspace.
- Create a new folder named 05-05-creating-shared-array-buffer.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js file with a main method that defines constants for NUM_COUNT, BYTES_FOR_32_BIT, ARRAY_SIZE, and MAX_NUMBER:
export function main() { const NUM_COUNT = 2048; const BYTES_FOR_32_BIT = 4; const ARRAY_SIZE = NUM_COUNT * BYTES_FOR_32_BIT; const MAX_NUMBER = 1024; }
- Next, create a SharedArrayBuffer that is of size ARRAY_SIZE, and create an Int32Array casting of it:
export function main() { // ... const sab = new SharedArrayBuffer(ARRAY_SIZE); const intBuffer = new Int32Array(sab); }
- Fill the intBuffer ...