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

some questions #134

Open
kanli201904 opened this issue Sep 1, 2022 · 3 comments
Open

some questions #134

kanli201904 opened this issue Sep 1, 2022 · 3 comments
Labels

Comments

@kanli201904
Copy link

Hello: if the dequeue work very slowly, the queue will become bigger and bigger, is there some limit or max level for the queue? can we delete the element

@cameron314
Copy link
Owner

It sounds like you want a circular ring-buffer that supports elements being overwritten on overflow.

It is not possible to overwrite elements with my queue, however you can limit the number of elements using either the BlockingReaderWriterCircularBuffer or ReaderWriterQueue with try_enqueue (with an appropriate size passed to the constructor).

@samdafi
Copy link

samdafi commented Jan 6, 2024

@cameron314 an overwriting circular buffer would be very useful for audio (DSP->GUI thread) visualizations, which is a fairly common scenario for me. I did think about this a fair bit and dug through the circular buffer code, but decided that while it would be cool to pop if there were no slots left during an enqueue, there's no thread safe way to do this from the producer thread. Does your answer here confirm that?

In that particular case, and when limited to scalars, I wonder if a simple array of std::atomic using the power of two mask trick for modulo would suffice 🤔

@cameron314
Copy link
Owner

Right, not really feasible with the current design. Yes, this could be done for std::atomic integers, though the reader/writer indexes would need to be coordinated somehow.

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

No branches or pull requests

3 participants