Boost logo

Boost Users :

Subject: Re: [Boost-users] [circular_buffer] About overwriting elements
From: Jan Gaspar (jano_gaspar_at_[hidden])
Date: 2010-04-19 06:55:02


Yes, that behaviour is expected. When the circular buffer is empty read_pos points to the end. After you put some items into it read_pos will point to the begining. In your case I would recommend you not to rely on iterators as they may get invalidated. Instead, in you read operation rely on array_one() and after that clear the whole circular buffer. Jan ----- Original Message ---- From: Daniele Barzotti <daniele.barzotti_at_[hidden]> To: boost-users_at_[hidden] Sent: Mon, 19 April, 2010 11:44:14 Subject: Re: [Boost-users] [circular_buffer] About overwriting elements 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 mailing list Boost-users_at_[hidden] http://lists.boost.org/mailman/listinfo.cgi/boost-users


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