circular buffer in C++

Discussion in 'C++' started by marco.furlan@syac.com, Oct 20, 2006.

  1. Guest

    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
     
    , Oct 20, 2006
    #1
    1. Advertising

  2. mlimber Guest

    wrote:
    > 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.net/boost-sandbox/boost-sandbox/boost/

    Look at circular_buffer.hpp and the circular_buffer subdir.

    Cheers! --M
     
    mlimber, Oct 20, 2006
    #2
    1. Advertising

  3. Joe Seigh Guest

    mlimber wrote:
    > wrote:
    >
    >>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.net/boost-sandbox/boost-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/circular_buffer.html#boundedbuffer


    --
    Joe Seigh

    When you get lemons, you make lemonade.
    When you get hardware, you make software.
     
    Joe Seigh, Oct 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raja
    Replies:
    12
    Views:
    24,703
    John Harrison
    Jun 21, 2004
  2. Kiuhnm
    Replies:
    16
    Views:
    761
    Jonathan Mcdougall
    Jan 3, 2005
  3. toton
    Replies:
    7
    Views:
    684
    toton
    Aug 8, 2006
  4. Sven
    Replies:
    12
    Views:
    1,390
    karthikbalaguru
    Nov 5, 2007
  5. Sam Dalton

    Synchronized Circular Buffer

    Sam Dalton, Jul 1, 2010, in forum: Ruby
    Replies:
    3
    Views:
    251
    Robert Klemme
    Jul 1, 2010
Loading...

Share This Page