-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed arrays #89
Comments
Do you have an example of what your trying to do? |
"Typed Array" is good and consume less memory than the "array " performance. "Typed Array" for reading and writing the file contents , as well as for data encryption and decryption. // From a length
var uint8 = new Uint8Array(2);
uint8[0] = 42;
console.log(uint8[0]); // 42
console.log(uint8.length); // 2
console.log(uint8.BYTES_PER_ELEMENT); // 1
// From an array
var arr = new Uint8Array([21,31]);
console.log(arr[1]); // 31
// From another TypedArray
var x = new Uint8Array([21, 31]);
var y = new Uint8Array(x);
console.log(y[0]); // 21
// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Uint8Array(buffer, 1, 4); |
Apart from the BYTES_PER_ELEMENT, that should just work. For the passing arrays in you'll need: #108 |
|
References: |
I thought about this briefly before. It would be nice to have with Go's natives types, but I don't know of a straightforward way (leveraging Go) to present "typed views" of the same data. |
There is a standard library way of treating arbitrary bytes as a sequence of fixed-size values: http://golang.org/pkg/encoding/binary/#Read It seems designed for bulk transform, not for providing a typed view of bytes. It might not perform very well if it gets called repeatedly, as you'd want to do for providing this interface. Docs for the package say "This package favors simplicity over efficiency." There's always the |
I got the error:
form gopherjs by the way When can we use the ArrayBuffer |
A little off topic, but Int32Array always gets converted to a []int? Even on a 64 bit machine where int means int64? |
@stevenh Does your comment mean that typed arrays are currently implemented in otto? When I try to to do something simple with types arrays (eg: |
Looking at the code a bit I'm reasonably confident that no attempt has been made to implement typed arrays. Could this limitation be documented in the caveat-emptor section of the README? |
Typed Arrays aren't part of ES5, and I don't think we need to start listing all the ES6 features otto doesn't support. |
That is fair, how about listing that otto targets ES5 then? Typed arrays are relatively ubiquitous at this point (more so than much of ES6) so this seems like it might be a common pitfall. |
Yep, fair call. I actually thought it was listed clearly already, but I appear to be mistaken! I'd happily merge a change to make this more obvious in the readme and the inline docs - could you put that in for me, @hochhaus? |
Typed arrays are part of ES6 so not currently supported, but it should be possible to do. |
When can support Typed arrays?
The text was updated successfully, but these errors were encountered: