Re: Circular buffer
- From: "saraca means ashoka tree" <sindica@xxxxxxxxx>
- Date: 9 Jun 2005 19:34:51 -0700
>If the writer is consistently faster than the reader, and the writer
> is blocked when the queue is full, the writer is forced to synchronize
> its speed with the reader. The result is no different than having a
> single element buffer instead of a queue. If the reader is
> consistently faster than the writer, the reader will block until the
> writer serves the queue. The reader is forced to synchronize with the
> writer, resulting in the same performance as is found with a single
> element buffer.
>
> The designer of the system now has two options: ensure every queue
> element
> is read before it is over-written (and read only once), or allow the
> writer to over-write unread messages and the reader to read
> already-read
> messages. If the first choice is taken, then a single element buffer
> will
> produce almost exactly the same performance as a circular queue, with a
> lot less complexity. If the second choice is taken the data in the
> circular queue must be protected from simultaneous reading and writing.
I think i have created some confusions. The circular buffer is self
contained. The system itself is pretty much tight on ensuring the
writer and reader threads are in sync (Using a flow control algorithm
).
Let me elaborate my problem. Say, i am interfacing my system to a
legacy sy
system which provides read access through an API. Where the read API
signature is approximately as shown below.
read(char* startptr, int numberofbytes_to_read, int
*numberofbytes_read);
The implementation of read API would actually start copying data to the
startptr. Here is the catch. I wish to give the startptr as the
"writeptr" of my circular buffer. If the *read* API had used my enque()
function of my circular buffer to copy the contents, i wouldn't have
had to worry at all. My bad, it is not. Instead it is using a memcpy.
My idea, is to start a monitor thread in the implementation of circular
buffer. So whenever the circular buffer is initiated the thread starts
and watches the progress of the writeptr (and possibly readptr) and
make sure that it doesn't collides with readptr and the pointers are
wraped around safely without permitting access to the border locations
of the array. Is this a good idea ?.
.
- References:
- Circular buffer
- From: saraca means ashoka tree
- Re: Circular buffer
- From: Thad Smith
- Re: Circular buffer
- From: jimmaureenrogers@xxxxxxxxxxxxxxxx
- Circular buffer
- Prev by Date: Re: Circular buffer
- Next by Date: puzzle
- Previous by thread: Re: Circular buffer
- Next by thread: Re: Circular buffer
- Index(es):
Relevant Pages
|
Loading