c++ - Using a shared_ptr into an unordered_set -
I am trying to cut the string copy (which was measured in my application to generate a performance constraint Is) the strings are In the above, only one instance of the string "foo" should be in string_pool; Both A and B should point out; And at the time that both A and A have been destroyed, "foo" should be erased from string_pool suggests, but I am not clear that the indicator Am I here on the right track? I need to keep string_pool from continuous to grow, but there is no point at which I can clean it, and there is no "master" of stars in it. UPDATE 1 History of this problem: This is a "traffic police" app that reads from the server, parceling data into other servers Receives their answer, parceles, receives others, and finally gathers and gives a brief answer. It contains a protocol stack that receives TCP messages, parsing them into string scalar values, which the application sends, sends, receives, and so on in other TCP messages. I basically use the As I have described in my comment on @PeterR, I was at least comfortable with semantics and containers and contexts till now, and it is quite possible that I had my simple code Can not use string-based solution to offer all C ++ 11 So far, I think traveling in a great circle. is the owner of an uneded_set string when it exits from the radius, your chars will be empty. My first impression is that your attitude does not sound, because of this there will be a positive experience with regards to liability or testability. Definitely it Incorrectly you already have a master for string in your unordered_set, it is not working on trying to keep another ownership layer on it with shared APRR. You have a Without understanding the rest of your code base, this is a 'solution' here. Combination of words of move and unordered_set & lt; String & gt; In and then
shared_ptr
unordered_set & lt; String & gt; String_pool; : Shared_ptr & lt; String & gt; A = & amp; (* String_pool.emplace ("foo"). Previously); // The first is an IETRATOR: shared_ptr & lt; String & gt; B = & amp; (* String_pool.emplace ("foo"). Previously);
one < Can be reborn due to the allocation of / code> pointer
b . It also guarantees that the second transfer of "foo" will not be the reason for any refinance because it is already present in the set.
string s, code> vectors & lt; String & gt; s, and string references, and Valgrind reported a "high number" of string constructors (even compiled with -33 ) , And high CPU usage which was centered in the library routine associated with strings. I was asked to check the methods of reducing string copies, and a "memref" class ( four * and the length pointing in the input buffer) was created, in return for the string Could be copied. After this, input buffer needs to be reused in the circumstances, as long as the memrefs still need to be valid, so I have given each buffer substrings a transfer area (a
unordered_set & lt; string & Gt; ), and instead of the memref point I came to know that in this process it was difficult and inconvenient to find a place, when the interval field was cleared once (To prevent its development without any obligation), and I started trying to redesign the area initially so that when all the members had an internal string gone, the string was removed from the pool. Therefore shared_ptr
shared_ptr
unordered_set & lt; Shared_ptr & lt; String & gt; & Gt; Maybe, but I will not even suggest it.
const string and should handle the highest requirements at a lower level. If there are still performance issues then they can be architectural, definitely only
shared_ptr
unordered_set & lt; Do not use string & gt; In that case.
Comments
Post a Comment