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 Yes, _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?
update
_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
Post a Comment