0

How is storing values directly in Javascript arrays is different than from storing them in come client side alternative like LocalStorage or 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.

1
  • You will most certainly be optimizing the rendering of data and possibly the client-side processing. That is your main bottlenecks, not the storage itself. Commented Oct 7, 2012 at 9:40

1 Answer 1

4

Obvious differences between localStorage and arrays are :

  • 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

You read and write in localStorage like this :

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

(example taken from the great introductory site http://diveintohtml5.info/storage.html)

If you're only using your data for the current session, don't use localStorage. Use standard arrays (they're fine and fast) or Float32Array.

Sign up to request clarification or add additional context in comments.

12 Comments

Why not use getItem() and setItem() methods instead?
Thanks a lot for reply. But my doubt goes unresolved. So, I have to store few thousand float values every second. And I want to store these for 2 minutes and discard values which are older than that. So, what is the right way ? Any harm in plainly storing them in a javascript array ? so it will be like 500kbps of data => 50-60 mb for 2 minutes.
Hi David, thanks for comment. Can you please elaborate a bit.
@David because the brace notation is cleaner and prettier... but you may if you want use getItem and setItem.
@user969107 There is no point in using localStorage to store data only for current session.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.