Implement a Thread Safe Circular Byte Buffer

  • Thread starter Thread starter shofu_au
  • Start date Start date
S

shofu_au

Dear readers,

Before poorly reinventing the wheel I thought I would ask if a class
already exists.

I need to use a circular byte buffer that is thread safe.

I cannot use MSMQ, my regular choice, due to complicated reasons -
don't go there.

This must be pretty common, so any suggestions on a good class to look
at or
pointers on rolling my own would be most appreciated.

Thanks

Mark
 
Before poorly reinventing the wheel I thought I would ask if a class
already exists.

I need to use a circular byte buffer that is thread safe.

I cannot use MSMQ, my regular choice, due to complicated reasons -
don't go there.

This must be pretty common, so any suggestions on a good class to look
at or pointers on rolling my own would be most appreciated.

I don't think it's terribly common, and I haven't come across one.
However, I have a queue implementation that's got random access, and
could easily be adapted. It's part of my MiscUtil library, and is open
source. You're welcome to adapt it to your purposes. Alternatively, if
you're happy to come up with a bunch of unit tests to show the
semantics you want, I could do the adaptation myself and make it
available to everyone :)

See http://pobox.com/~skeet/csharp/miscutil for the library.

Jon
 
Hi Readers,

I am in the process of rolling my own thread safe circular buffer.

My data is extracted from TCP packets and inserted it into the
circular buffer with the first word being the length of the message
which make it easy for the reader to know exactly how much data to
extract and process.

I am copying data in and out of the buffer useing the Buffer.Blockcopy
method.

Now to implement such a circular buffer that retreives the length of
the next message to extract from the buffer.

I need to zero out the all the bytes of the circualr buffer that I
just read.

What is the fast way to zero out a section of a byte buffer?

Currently, I expect to add 200 - 400 byte message at a peak of 100 per
second to my circular buffer and obviously extract in several seperate
processes at a higher rate.

Thanks

Mark
 
On Mar 30, 8:06 am, (e-mail address removed) wrote:

What is the fast way to zero out a section of a byte buffer?

(Apologies if this shows up twice.)

I expect Array.Clear would be pretty fast.

Jon
 
On Mar 30, 8:06 am, (e-mail address removed) wrote:

What is the fast way to zero out a section of a byte buffer?

I'd expect Array.Clear to be pretty nippy.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top