Coder Social home page Coder Social logo

Comments (10)

P-p-H-d avatar P-p-H-d commented on May 28, 2024

Yes, it is possible. It is indeed m-buffer (BUFFER_DEF with BUFFER_UNSAFE|BUFFER_QUEUE)
Why do you think it is not suitable?

from mlib.

vladipus avatar vladipus commented on May 28, 2024

I would imagine that a ring fixed-size buffer is something that loops its new last element all over again. Your implementation just rewrites the count - 1 element when the buffer is full.

from mlib.

P-p-H-d avatar P-p-H-d commented on May 28, 2024

I am not sure to understand what you mean.
BUFFER_DEF with a BUFFER_QUEUE implements a ring buffer as explained here: https://en.wikipedia.org/wiki/Circular_buffer

from mlib.

vladipus avatar vladipus commented on May 28, 2024

Does start and end pointers actually change in your implementation?

from mlib.

P-p-H-d avatar P-p-H-d commented on May 28, 2024

Yes

from mlib.

vladipus avatar vladipus commented on May 28, 2024

What happens when you push an element to a full queue?
I want a thread-unsafe ring-buffer and using BUFFER_PUSH_OVERWRITE also. The pushing seems to always overwrite the last element (count - 1)

from mlib.

vladipus avatar vladipus commented on May 28, 2024

I seem to miss the point, maybe. is BUFFER_PUSH_OVERWRITE mandatory for thread-unsafe buffers?

from mlib.

P-p-H-d avatar P-p-H-d commented on May 28, 2024

What happens when you push an element to a full queue?

It depends on the configuration of the queue. It may:

  • block until the queue is not full (if BUFFER_THREAD_SAFE)
  • overwrite the youngest element if BUFFER_PUSH_OVERWRITE
  • return a failure otherwise.

I want a thread-unsafe ring-buffer and using BUFFER_PUSH_OVERWRITE also. The pushing seems to always overwrite the last element (count - 1)

This is what BUFFER_PUSH_OVERWRITE does (overwrite the youngest element in case of buffer full) to avoid blocking.

is BUFFER_PUSH_OVERWRITE mandatory for thread-unsafe buffers?

No

from mlib.

vladipus avatar vladipus commented on May 28, 2024

Ok, I now seem to get it. Thank you.
But it still looks kinda un-optimal that atomic is used in a thread-unsafe version.
what do you think?
image

from mlib.

P-p-H-d avatar P-p-H-d commented on May 28, 2024

It is true! Thanks. I have opened an issue on it: #90

from mlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.