1

What are some scenarios where you would choose one over the other when programming in AssemblyScript?

In my case I am trying to build a K-d tree from a list of tuples of floating point numbers. Because I need to rearrange and sort the incoming list of tuples, my first go-to is using Array<Array<f64>> since I can easily add and remove data from it.[

chautelly
  • 447
  • 3
  • 14

1 Answers1

1

Your intuition is correct, the standard array is the most flexible.

In Assemblyscript there are three array types.

Array

let a:f32[] = [0,1,2]

  • Resizable
  • Can hold references
  • The least performant

Static Array

let a:StaticArray<f32> = [0,1,2]

  • Fixed size
  • Can hold references
  • Great performance

Typed Array

let a:Float32Array = new Float32Array(3)

  • Fixed size
  • Can hold numeric values only
  • Great performance
  • Buffer access for shared views etc

Note - it is not currently possible to initialize a typed array with values, ie

new Float32Array([0,1,2])

chantey
  • 4,252
  • 1
  • 35
  • 40