Opened 12 years ago

Closed 12 years ago

#4603 closed Bugs (invalid)

circular_buffer_space_optimized does not grow when capacity runs out

Reported by: daniel.amthauer@… Owned by: Jan Gaspar
Milestone: To Be Determined Component: circular_buffer
Version: Boost 1.43.0 Severity: Problem
Keywords: Cc:

Description

Contrary to what the documentation specifies, circular_buffer_space_optimized does not grow when capacity runs out.

The problem seems to be in line 1243 of space_optimized.hpp:

1239        //! Ensure the reserve for possible growth up.
1240        size_type ensure_reserve(size_type new_capacity, size_type buffer_size) const {
1241            if (buffer_size + new_capacity / 5 >= new_capacity)
1242                new_capacity *= 2; // ensure at least 20% reserve
                /// shouldn't this be less-than?
1243            if (new_capacity > m_capacity_ctrl)
1244                return m_capacity_ctrl;
1245            return new_capacity;
1246        }

I've tested changing the "greater-than" sign on line 1243 to a "less-than" and that works fine.

Change History (2)

comment:1 by anonymous, 12 years ago

I believe the code is right. If you create a space optimized circular buffer of a particular capacity e.g. of 10 elements it's capacity should remain unchanged (unless it is changed explicitly). When you normally instantiate the space optimized buffer the allocated memory (internal capacity) is zero. As you fill the buffer with elements the internal capacity grows but upto 10 elements. When you insert more than 10 elements then the oldest elements get overwriten. (And vice versa if you remove the elemens from the buffer the allocated memory slowly decreases.)

Hope this makes sense.

Jan

comment:2 by Jan Gaspar, 12 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.