c++ - Reference-counting of std::string -


After

I'm looking into the code for basic_string (that comes with G ++ 4.2 .1).

  _CharT * _M_grab (constant: copy creator a  grab ()  use "grab" a copy of a string (also increase its reference number) Does _Alloc & __alloc1, constants _Alloc & amp; __alloc2) {return & _M_is_leaked (!); & Amp; __alloc1 == __alloc2)? _M_Recopio (): _M_clone (__alloc1); }  

This only increases the reference-count if the allotment is equal to two strings - it is understandable. However, the copy maker is:

  basic_string (constants basic_string & amp; __str): _M_dataplus (__ str._M_rep () -> _M_grab (_Alloc (__ str.get_allocator ()), __str.get_allocator (__str.get_allocator), __str.get_allocator ()) {}  

The first attacker that has passed for _M_grab () is a copy of the second. Why? The only way that the operator == () for allocation can be false if the user is using the custom allocator though, even if it is true So, would you think that a copy allocation will compare to its original, equal parallel? so?

  1. Why compare allocators at all
  2. Why copy a negative copy and
  3. Copy the original to compare what is a use-if any copy If compared to its original, then will the false return?

    update

    Yes, _M_grab () is used in another location: in this case for assignment, the algorithm _M_grab () are differently okay But there is still no reason to make a copy, then compare allocators for constructor in string .

I know about the argument of the GCC team but this is my presentations:

< Ol>
  • For debugging? Allocations must be required.

  • So can it use _M_grab ()?

  • Should never be?


  • Comments

    Popular posts from this blog

    c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

    Calling GetGUIThreadInfo from Outlook VBA -

    Obfuscating Python code? -