[vdr] Re: cString operator= with same buffer
mws at twisted-brains.org
Sun Nov 20 22:16:58 CET 2005
On Sunday 20 November 2005 22:07, Jon Burgess wrote:
> Sascha Volkenandt wrote:
> > Would you mind to explain how you get two strings pointing to the same buffer
> > after the copy ctor is safe (makes a copy instead of taking the buffer)? IMHO
> > the copy ctor already takes care that doesn't happen (except if you hand over
> > the same buffer to two cStrings with TakePointer = true, which is IMHO not
> > intended).
> As you say, all normal usage should be between 2 different buffers. It
> doesn't seem legal to me that 2 cStings would share the same buffer.
> This would always cause things to blow up when the destructors are called.
> The only way that I can come up with is to assign a cString to itself
> (as per my example main.c elsewhere in this thread). I imagine this
> could happen legally under some limited circumstances.
> I don't know the details of the scenario seen by Holger.
sometimes this is done with a sense.
if you have a look at the standard template library,
you'll find out that the strings - exactly the content -
is shared by refcounting and a copy is just done, if it is needed.
i had a short look at the tools.c/h files and closed them fast again.
imho mixing up c & c++ permanently is not a good style at all.
have a look at std::basic_string.
it is working with copy_on_write.
just my 2ct
More information about the vdr