Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

c++ - Standard container re-allocation multipliers across popular toolchains

Containers like std::basic_string and std::vector perform automatic re-allocations when internal capacity runs out. The standard specifies that, after a re-allocation, .capacity() >= .size().

What are some of the actual multipliers used by mainstream toolchains when performing re-allocations?


Update

So far, I have:

Dinkumware: 1.5 (ships with MSVS and possibly ICC)

GNU libstdc++: 2 (ships with GCC and possibly ICC)

RW/Apache stdcxx: 1.618 (aka φ)

STLport: 2

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Dinkumware STL (shipped with Visual Studio) uses a 1.5 multiplier, Gcc uses 2. I cannot really tell for the rest, but I think those are the most often used numbers. (IIRC, I read once that most implementations used 2)

As a side comment, you are correctly calling it a multiplier since the standard requires the growth to be (at least) geometrical.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...