Hacker News new | ask | show | jobs
by mraleph 5085 days ago
You can use one Float32Array: x component gets even indices, y gets odd ones.

The next standard might have a better binary data support:

http://wiki.ecmascript.org/doku.php?id=harmony:binary_data

I am not sure though where you tradeoffs between expressibility and performance. Typed arrays came to our world only recently, when needs of WebGL gave them birth. So they ended up being bolted on top of an existing language.

1 comments

"You can use one Float32Array: x component gets even indices, y gets odd ones."

That is exactly my point of choosing the performance vs expressibility. But then how do I write algorithms in a generic fashion for them? In C++ I have templates and template functions, so I can write algorithm that will work for any type of the array. And I'm not even talking about STL which decouples algorithms from containers, by making the latter provide a hierarchy of iterators. Other languages like Haskell also provide compile-time polymorphism. And here we are in 2012 - there is an ad-hoc solution that only works in few browsers, and a proper one is only down the road.