Connecting Tech Pros Worldwide Help | Site Map

circular buffer in C++

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 20th, 2006, 12:35 PM
marco.furlan@syac.com
Guest
 
Posts: n/a
Default circular buffer in C++

Hi there,
I have to write an optimized circular buffer to log events in C++. The
elements are of type std::string. This should run under Linux on an ARM
embedded system. I can dedicate to this circular log a preallocated
block of fixed size and work in there.
Can anybody indicate me an example or technique to do this ?

Thanks

Marco


  #2  
Old October 20th, 2006, 12:35 PM
mlimber
Guest
 
Posts: n/a
Default Re: circular buffer in C++

marco.fur...@syac.com wrote:
Quote:
Hi there,
I have to write an optimized circular buffer to log events in C++. The
elements are of type std::string. This should run under Linux on an ARM
embedded system. I can dedicate to this circular log a preallocated
block of fixed size and work in there.
Can anybody indicate me an example or technique to do this ?
Check out the circular buffer that will soon be part of Boost. The docs
can be found (in a slightly dated form) here:

http://myweb.tiscali.co.uk/gaspar/circular_buffer.html

and the code can be found in the Boost sandbox:

http://boost-sandbox.cvs.sourceforge...sandbox/boost/

Look at circular_buffer.hpp and the circular_buffer subdir.

Cheers! --M

  #3  
Old October 22nd, 2006, 11:55 AM
Joe Seigh
Guest
 
Posts: n/a
Default Re: circular buffer in C++

mlimber wrote:
Quote:
marco.fur...@syac.com wrote:
>
Quote:
>>Hi there,
>>I have to write an optimized circular buffer to log events in C++. The
>>elements are of type std::string. This should run under Linux on an ARM
>>embedded system. I can dedicate to this circular log a preallocated
>>block of fixed size and work in there.
>>Can anybody indicate me an example or technique to do this ?
>
>
Check out the circular buffer that will soon be part of Boost. The docs
can be found (in a slightly dated form) here:
>
http://myweb.tiscali.co.uk/gaspar/circular_buffer.html
>
and the code can be found in the Boost sandbox:
>
http://boost-sandbox.cvs.sourceforge...sandbox/boost/
>
Look at circular_buffer.hpp and the circular_buffer subdir.
>
I don't know if it's too clear here, but a circular buffer is actually
two logical queues. So a pop from a circular buffer is a pop from the
full queue and a simultaneous push into the empty queue. In multi-threading
that means you have to push and pop by value. In particular, if you pop
by reference, the value you are referencing can be modified by another
thread so you want to avoid that. The OP wants to use strings and wants
to avoid buffer allocation and deallocation so I imagine that means
deep copying of strings. The internal refcounted string implementations
that don't deep copy would probably involve too much allocation/deallocation
overhead.

The example here probably wouldn't work for the OP's purpose if they're
multi-threading.
http://myweb.tiscali.co.uk/gaspar/ci...#boundedbuffer


--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.