开发者

Collecting, storing, and retrieving sensor data

开发者 https://www.devze.com 2023-04-12 05:39 出处:网络
I\'m developing an app which needs access to \'the last 5 seconds worth of data\' for a giv开发者_开发问答en sensor. My plan is to store this data somehow, then when I request the data, it\'ll return

I'm developing an app which needs access to 'the last 5 seconds worth of data' for a giv开发者_开发问答en sensor. My plan is to store this data somehow, then when I request the data, it'll return any data obtained within the last 5 seconds. I'm not sure how to do this effectively, given that:

  1. Dalvik doesn't like having lots of objects being created, so I can't make an object for each sensor reading which contains the value + timestamp.

  2. I need to be constantly storing new data in some sort of structure, whilst retrieving a specific portion of it.

My only other requirement is that data which is older than 5 seconds should be disposed of. This isn't really critical, but I imagine retaining the data would eat at memory.

I currently have a onSensorChanged listener set up, so I don't need help with that.

Any ideas?


maybe pre-allocate enough objects to store 5 seconds of data and store them in a pool. get objects from the pool, add time stamp and value and insert into sorted set. remove any old objects after you insert a one and put them back into the pool. or maybe you can get by with just a circular buffer http://en.wikipedia.org/wiki/Circular_buffer

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号