sliding window containing n seconds of data
I'm looking for a way to examine an array of object structures for an adjustable window of n seconds. My application reads objects at a high rate (which I'll have to throttle), and I'd then like to put them onto an array. My thinking is to assign a timer on each object that is initialized to n seconds and once the timer expires, the object is removed from the array, but while it's on the array, I'll iterate over the objects looking for the info I need. I put this out on the boost list as I suspect boost has the mechanisms to handle this and someone could suggest a good way of going about it. Any help much appreciated.
Look into boost/circular buffer -- View this message in context: http://boost.2283326.n4.nabble.com/sliding-window-containing-n-seconds-of-da... Sent from the Boost - Users mailing list archive at Nabble.com.
I like the idea of using a circular_buffer, but still not sure how to time
the data on this buffer. I'd like for objects on this buffer to be removed
after n seconds, and not based on fixed capacity where they get
over-written. Or did I misunderstand? I think somehow attaching a timer to
each and every object on this buffer is the part I'm having trouble with
efficiently.
On Tue, Apr 21, 2015 at 10:51 PM, Robert Ramey
Look into boost/circular buffer
-- View this message in context: http://boost.2283326.n4.nabble.com/sliding-window-containing-n-seconds-of-da... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wednesday, April 22, 2015 12:22 PM, Lane wrote:
I like the idea of using a circular_buffer, but still not sure how to time the data on this buffer. I'd like for objects on this buffer to be removed after n seconds, and not based on fixed capacity where they get over-written. Or did I misunderstand? I think somehow attaching a timer to each and every object on this buffer is the part I'm having trouble with efficiently.
I don't think you need to remove them after n seconds, you just need to not read entries older than n seconds, so perhaps store the data with a timestamp, and then clean up or ignore old entries during the read. Ben
On April 22, 2015 1:10:12 AM EDT, Ben Pope
I like the idea of using a circular_buffer, but still not sure how to time the data on this buffer. I'd like for objects on this buffer to be removed after n seconds, and not based on fixed capacity where they get over-written. Or did I misunderstand? I think somehow attaching a timer to each and every object on this buffer is the part I'm having
On Wednesday, April 22, 2015 12:22 PM, Lane wrote: trouble
with efficiently.
I don't think you need to remove them after n seconds, you just need to
not read entries older than n seconds, so perhaps store the data with a
timestamp, and then clean up or ignore old entries during the read.
Seems like a fairly straightforward thing to do with vectors and iterators? That's standard C++, nothing boost-y about that. Use the algorithms if necessary. Or boost.range if necessary. Possibly lockfree to help with new versus expired items, etc.
Ben
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Sent from my Android device with K-9 Mail. Please excuse my brevity.
On 04/22/2015 06:22 AM, Lane wrote:
I like the idea of using a circular_buffer, but still not sure how to time the data on this buffer. I'd like for objects on this buffer to be removed after n seconds, and not based on fixed capacity where they get
Your understanding of circular_buffer is correct, but IIUC you wish to throttle the rate of objects per time, so it makes more sense to limit the number of objects in the queue than the time interval. This is also significantly easier to implement.
over-written. Or did I misunderstand? I think somehow attaching a timer to each and every object on this buffer is the part I'm having trouble with efficiently.
As others have already mentioned, you can simply leave them in the queue and let the consumer discard outdated objects when they are extracted.
participants (5)
-
Ben Pope
-
Bjorn Reese
-
Lane
-
Michael
-
Robert Ramey