简体   繁体   English

用于在javascript中存储对象的类型化数组

[英]Typed array for storing objects in javascript

I have been using typed arrays like Int32Array in javascript. 我一直在使用JavaScript中的Int32Array之类的类型化数组。 I want to implement a circular queue using javascript and don't want to compromise on performance. 我想使用javascript实现循环队列,并且不想在性能上有所妥协。

The problem is that the queue items are of Javascript Object type and so I can't save them in the simple Array object. 问题在于队列项目属于Javascript Object类型,因此我无法将其保存在简单的Array对象中。 Thus I need a Typed Array which can perform really well with JS Object type objects. 因此,我需要一个Typed Array,它可以与JS Object类型的对象一起很好地执行。

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 更新:从评论看来,人们似乎不太清楚使用类型化数组的性能优势,因此我创建了此js perf测试,以使其更加明显

http://jsperf.com/typed-array-vs-normal-array http://jsperf.com/typed-array-vs-normal-array

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. “对象”是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. 因此,根据定义,对象的类型化数组将不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM