Register Now! (to share your work)[Help]
[|]|

// (U8 @ #u8) ready.
// Libraries bound - Libraries.txt
Note on S8TypedArrays
S8TypedArrays was build as a wrapper of Javascript Typed Arrays. At the moment Javascript Typed Arrays is not yet widely supported, (see this page for more details), but is expected to be a common feature in modern browsers.
A primary version of S8TypedArrays is available for download here.


Some notes
S8TypedArrays classes are: ArrayBufferView , TypedArray, ArrayDataView, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, ArrayBuffer.

The framework has minimal programming facilities. Methods like #at:ifAbsent: , #= , #do: , #collect:, and #, are available across TypedArray hierarchy.

Althouhg ArrayBuffer class is present and implemented it is not promoted operate over ArrayBuffer instance. Instead, you have specific classes (Float32Array, Uint8Array, etc) to work with.

Typical usages are:

[1]

| aFloat32Array |

aFloat32Array := Float32Array new:4.
aFloat32Array at:1 put: 0.1.
aFloat32Array at:2 put: 0.2.
aFloat32Array at:3 put: 0.3.
aFloat32Array at:3 put: 0.4.


[2]

| anArray aFlt32 otherFlt32 |

anArray := #(0.1 0.2).
aFlt32 := Float32Array fromArray: anArray.
otherFlt32 := Float32Array fromArray: #(10.92 5.6 6.7998 1.009).

[3]

| anArrayBuffer aUInt8 |

anArrayBuffer := ArrayBuffer new:8.
aInt32 := UInt8Array fromArrayBuffer: anArrayBuffer byteOffset: 1 length: (anArrayBuffer size).


[1], [2], [3] diferent kinds of instance creation. As defined in oficial spec any concrete typed array has an ArrayBuffer as a place holder for low level data (bytes). A direct handling of an ArrayBuffer is not encouraged, you should access to ArrayBuffer contents through an specific typed array.
Multiple typed arrays can refer to the same ArrayBuffer, of different types, lengths, and offsets. This allows for complex data structures to be built up in the ArrayBuffer. For example:

[4]

| anArrayBuffer aUInt8 aInt32 aInt16 |

anArrayBuffer := ArrayBuffer new:8.
aInt32 := Int32Array fromArrayBuffer: anArrayBuffer.
aUInt8 := UInt8Array fromArrayBuffer: anArrayBuffer byteOffset: 2.
aInt16 := Int16Array fromArrayBuffer: anArrayBuffer byteOffset: 2 length: 2.


On this way it is posible to have a a single contiguous buffer, with interleaved data types. For example, a point might have coordinate data (3 Float32 values) followed by color data (4 Uint8 values).

For 4 points and their associated colors, this can be set up in the following way:

| elementSize buffer coords colors |

elementSize := 3 * Float32Array bytesPerElement + 4 * Uint8Array bytesPerElement.
buffer := ArrayBuffer new: (4* elementSize).
coords := Float32Array fromArrayBuffer: buffer.
colors := Uint8Array fromArrayBuffer: buffer byteOffset: (3 * Float32Array bytesPerElement).


Typed arrays dont have a way to explicitly encode the desired per-point structure, so some manual arithmetic must be done to correctly index into the right values.