I am using the circular buffer container to hold up to 10000 std string objects.  I am finding that once the buffer has reached max capacity, memory continues to be consumed as I push new strings in.  Is there something I’m missing?  I stepped into the boost code and it does make a copy of the string using the std string operator so I would think it handles the string copy properly.  The size of the strings are variable but I would expect the memory usage to be fairly stable when the buffer is full but that is not the case.

 

Here’s basic usage

 

Definition:

 

      boost::circular_buffer<std::string> m_message_buffer;

 

Initialization:

 

      m_message_buffer.set_capacity (10000);

 

Usage:

 

void myClass::writeToBuffer (const char *message)

{

      m_message_buffer.push_back (string (message));

}

 

Boost code:

 

    void push_back(param_value_type item = value_type()) {

        if (full()) {

            if (empty())

                return;

            replace(m_last, item);

            increment(m_last);

            m_first = m_last;

        } else {

            m_alloc.construct(m_last, item);

            increment(m_last);

            ++m_size;

        }

    }

 

 

    void replace(pointer pos, param_value_type item) {

        *pos = item;

#if BOOST_CB_ENABLE_DEBUG

        invalidate_iterators(iterator(this, pos));

#endif

    }