Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add() (or new push()) that overwrites oldest? #10

Open
Humancell opened this issue Jul 12, 2019 · 5 comments
Open

add() (or new push()) that overwrites oldest? #10

Humancell opened this issue Jul 12, 2019 · 5 comments

Comments

@Humancell
Copy link

I'm curious if there is a way to add an option to add(), or a new call (push()?) that would always add to the queue by "pushing" the oldest item out of the queue?

In the current implementation it appears that if we are adding and the buffer fills, we are forced to lose the "new" items. This works in two of our cases, but we have one where we want the "oldest" data to be lost so that the queue contains the latest {x} records.

Does this make sense? Thoughts?

@wizard97
Copy link
Owner

This version currently does not have that behavior, but I would definitely see the use case for this. Maybe this will fit your needs? wizard97/Embedded_RingBuf_CPP#12

@Humancell
Copy link
Author

Humancell commented Jul 13, 2019

Yes ... your new feature would do what I am looking for:

bool addForce(const Type &obj)

Is this now a part of your next release?

@wizard97
Copy link
Owner

I don't currently have plans to add it, but you are welcome to add it in and submit a pull request.

@Humancell
Copy link
Author

Ok ... but I'm confused about what I am looking at (not as well versed at Github as I'd like to be) ... who wrote this code that you linked to, and can't you pull that into your project?

@wizard97
Copy link
Owner

wizard97 commented Jul 17, 2019

I made both of these projects, they both do the same thing. This one uses only C, the other one takes advantage of C++ features.

I think it will just be easier for you if you use my other project (https://github.com/wizard97/Embedded_RingBuf_CPP). The add method has the following signature

bool add(const Type &obj, bool overwrite=false)

If you call this method with overwrite set to true, then this will overwrite the oldest element when the buffer is full.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants