简体   繁体   English

在javascript数组中存储vs.(LocalStorage和IndexDB)

[英]Storing in javascript array vs. (LocalStorage and IndexDB)

How is storing values directly in Javascript arrays is different than from storing them in come client side alternative like LocalStorage or IndexDB. 将值直接存储在Javascript数组中的方式与将其存储在客户端替代方案(如LocalStorage或IndexDB)中的方式不同。

Where the values get stored in either cases. 在两种情况下都将值存储在何处。 And what are limits. 还有什么限制。

My use case is: to store very fast data (float values) coming from server somewhere and then read it from that middle source to render the points on a real time plot/graph. 我的用例是:存储来自服务器某处的非常快的数据(浮点值),然后从中间源读取它,以在实时绘图/图形上绘制点。 Does the frequency also makes a difference to the choice ? 频率对选择也有影响吗?

Any sample code snippet will be of great use. 任何示例代码片段都将很有用。

Obvious differences between localStorage and arrays are : localStorage和数组之间的明显区别是:

  • you can only store strings (no objects) 您只能存储字符串(无对象)
  • it's persisted so that you'll get your values back next time 它会持续存在,以便您下次重新获得自己的价值观
  • as it writes on disk it's a heavier operation 当它写在磁盘上时,这是一个繁重的操作
  • the available space is limited to avoid cluttering the user's disk ( "User agents should limit the total amount of space allowed for storage areas.[...] A mostly arbitrary limit of five megabytes per origin is recommended" ) 为了避免使用户磁盘混乱而限制了可用空间( “用户代理应限制存储区域所允许的总空间量。建议每个来源的最大随机限制为五兆字节”

W3.org reference on localStorage W3.org在localStorage上的参考

You read and write in localStorage like this : 您像这样在localStorage中读写:

var foo = localStorage["bar"];
// ...
localStorage["bar"] = foo;

(example taken from the great introductory site http://diveintohtml5.info/storage.html ) (示例摘自出色的入门网站http://diveintohtml5.info/storage.html

If you're only using your data for the current session, don't use localStorage . 如果仅在当前会话中使用数据,则不要使用localStorage Use standard arrays (they're fine and fast) or Float32Array . 使用标准数组(很好且快速)或Float32Array

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

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