On Dec 11, 8:39*am, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:
> On Sun, 2011-12-11, Krzysztof Poc wrote:
> > Hi
>
> > I found that std::string keeps its string buffer on a heap. When a
> > string
> > object is passed to a function by value then the new string object is
> > allocated but it still points to the same string buffer allocated on a
> > heap.
> ...
> > From all above I conclude that the most reasonable way to pass a
> > string is by value (not a reference or pointer).
>
> Why?
>
> I use this rule: if I can choose between pass-by-value and passing a
> const reference, I only pass by value if the object is obviously
> small, a builtin type like an int or a pointer.
This is what I use also.
>
> There is no large category of classes in C++ which are guaranteed to
> use copy-on-write. It is not a very common design, IME.
>
Agreed.
Brian Wood
Ebenezer Enterprises
http://webEbenezer.net