How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 05-05-creating-shared-array-buffer.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  1. 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; 
} 
  1. 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);
}  
  1. Fill the intBuffer ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.