Skip to main content


Topic: JavaScript's TypedArrays and Sphere's ByteArrays. (Read 3041 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
JavaScript's TypedArrays and Sphere's ByteArrays.
For a long time, it was basically impossible to work with binary data natively in JS. Sphere solved this problem with a custom object, the ByteArray.

But time's change, and rooms are rearranged. Now we have TypedArrays, which are explicitly meant for the same task.

I've written a script that implements the ByteArray object using TypedArrays. I intend this to be the basis of the implementation of ByteArrays in TurboSphere, especially because TurboSphere will use TypedArrays in its API instead of ByteArrays.
  • Last Edit: September 09, 2014, 06:24:59 pm by Flying Jester

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #1
Also seems like it could be useful in a web implementation of Sphere, this.

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #2
Yea, this will likely be the web shim for ByteArrays, but its use of typed arrays will almost certainly exclude older browsers which can't or don't support typed array shims. Thanks for doing the work!

Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #3
So, I'm using this to read map files, and I've uncovered a couple problems with this implementation.

I'll post an updated version of this once I get everything working nicely, but there is one major issue with this implementation. A large ArrayBuffer will blow out the JS stack. I'm testing using Kefka's Revenge and Trial & Error maps, and almost all of them are too big to fully buffer into a JS array as I do here, since you can end up with a few arrays on the stack, all as big as the ArrayBuffer is. The more elegant solution that I didn't realize at the time is to just use the Uint8Array.buffer.slice() method.