Boost logo

Boost Users :

Subject: Re: [Boost-users] [circular_buffer] About overwriting elements
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2010-04-19 05:44:14


Il 16/04/2010 17:28, Jan Gaspar ha scritto:
> Hi Daniele,
>
> The circular_buffer behaves like a sliding window -
> which is what you don't want apparently.
> If you want the behaviour you described have a look at array_one()
> and array_two() methods.

Hi,
in my code I have this struct:

template<typename T>
struct TBuffer
{
  boost::circular_buffer<T> data;
  iterator write_pos;
  iterator read_pos;

  TBuffer(){ write_pos = data.begin(); read_pos = data.begin(); };
};

Then, when I write to it *(when it's still empty!)*:

size_type Write(const T* pData, size_type items)
{
...

  buffer_.read_pos = buffer_.data.begin();

  if (buffer_.read_pos == buffer_.data.begin())
    cout << endl << "THIS IS TRUE.." << endl;

  std::copy(pData,
            pData + items,
            back_inserter(buffer_.data));

  // Move the write cursor to the next position
  buffer_.write_pos = buffer_.data.begin() + items;

  if (buffer_.read_pos == buffer_.data.begin())
    cout << endl << "THIS IS NO MORE TRUE!!!" << endl
...
}

After inserting the elements, the begin() iterator changes and is no
more equal to the buffer_.read_pos iterator!
Is it normal?!

Regards,
Daniele.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net