Bird
0
0

How can you create a shared memory buffer that holds 10 floating-point numbers for multiple threads?

hard📝 Application Q9 of 15
Node.js - Worker Threads
How can you create a shared memory buffer that holds 10 floating-point numbers for multiple threads?
ACreate a SharedArrayBuffer of 10 bytes and a Float32Array view.
BCreate a SharedArrayBuffer of 80 bytes and a Float64Array view on it.
CCreate a SharedArrayBuffer of 40 bytes and a Float32Array view on it.
DCreate a regular Array of 10 floats and share it.
Step-by-Step Solution
Solution:
  1. Step 1: Calculate required buffer size

    Float32 uses 4 bytes per number; 10 numbers need 40 bytes.
  2. Step 2: Match buffer size and typed array

    Create SharedArrayBuffer(40) and Float32Array view to hold 10 floats.
  3. Final Answer:

    Create a SharedArrayBuffer of 40 bytes and a Float32Array view on it. -> Option C
  4. Quick Check:

    Correct buffer size and view = D [OK]
Quick Trick: Float32 = 4 bytes; multiply by count for buffer size [OK]
Common Mistakes:
  • Using wrong byte size for floats
  • Using regular Array instead of SharedArrayBuffer
  • Creating too small buffer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes