Question

I'm developing an app which needs access to 'the last 5 seconds worth of data' for a given 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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top