Reputation: 10992
I have been using typed arrays like Int32Array in javascript. I want to implement a circular queue using javascript and don't want to compromise on performance.
The problem is that the queue items are of Javascript Object
type and so I can't save them in the simple Array
object. Thus I need a Typed Array which can perform really well with JS Object
type objects.
Regards.
Update: From the comments it seems like people are not clear about the performance benefits of having a typed array so I created this js perf test to make is more apparent
http://jsperf.com/typed-array-vs-normal-array
Upvotes: 3
Views: 1083
Reputation: 14269
Typed arrays are there for efficiently storing primitive values. They are not based on a mechanism which magically improves performance. It is fast because it knows the type and the length of the stored value. "Object" is the base "type" in JavaScript. It's like the interface{} in go. You don't know too much about the "object" to store it efficiently. Therefore a typed array for an object can't exist by definition.
Upvotes: 5