Boost logo

Boost Users :

Subject: Re: [Boost-users] Question regarding circular buffer usage
From: Salivar.William (William.Salivar_at_[hidden])
Date: 2013-02-04 14:13:14


I am developing this under QNX with gcc 4.4.2 using Dinkum libraries (STL). To monitor heap usage, I am using a proprietary process that runs concurrently and monitors heaps usage of all process running on the system, similar to the QNX hogs utility but with heap monitoring.

From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Travis Gockel
Sent: Friday, February 01, 2013 10:12 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Question regarding circular buffer usage

What you are seeing is most likely caused by your malloc or string implementation (most likely not a bug, just an observation that differs from what you would expect). If your strings are of variable size, memory will most likely grow due to heap fragmentation. This should not grow unbounded, since after the second pass through the loop, the chunk of memory occupied by the first strings should be freed.

To show that circular_buffer works as documented, try a more simple object like this:

int allocations = 0;

struct AllocCountingObj
{
    AllocCountingObj()
    {
        ++allocations;
    }

    AllocCountingObj(const AllocCountingObj&)
    {
        // still increment on copy-construct
        ++allocations;
    }

    ~AllocCountingObj()
    {
        --allocations;
    }
};

What compiler and STL implementation are you using and what are you using to view the memory use?
On Fri, Feb 1, 2013 at 2:59 PM, Salivar.William <William.Salivar_at_[hidden]<mailto:William.Salivar_at_[hidden]>> wrote:
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
    }

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]<mailto:Boost-users_at_[hidden]>
http://lists.boost.org/mailman/listinfo.cgi/boost-users

--
Travis Gockel
ë Combinator


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