This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On Tue, 2004-02-03 at 05:41, Paolo Carlini wrote:Gabriel Dos Reis wrote:
if the only thing you have is a genuine input iterator you're effectively stuck. However, if you have at least a bidirectional iterator, then you can have an idea of the amount staorage you need. We already have dispatchers that compute those iterator categories. It might be a good idea to take advantage of them.
Ok. I think that, by and large, we already do our best, both in string and in vector...
A detail comes to my mind, though: perhaps, at construction time, speed matters more and, in the case of the constructor from input iterators, we should allow for a bigger factor. Later, memory usage matters more and a smaller factor seem in order (-> as you say, if the max speed is really needed reserve is always available, then).
Yes. This seems to me to be a really nice suggestion! Make the growth factor inversely proportional to the size of the vector.
Exercises for the reader: 1. If you've got a growth factor g, then the number of copies you have to make when adding N elements, one at a time, approaches k N. Find k as a function of g.
(I know the answer to exercise 1. I don't know the answer to exercise 2. My guess would be something like N log N, because this problem feels more or less like the integral of 1/x.)
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |