I am working on an old MFC / C ++ project that parses large text files using the MFC CString class to process strings. I noticed that during the parsing process, there are many additions of small details to the overall large CString object as such:
//'strContainer' = CString //'tag' = CString of a much smaller size strContainer += L"<" + tag + L">";
The above statement slows down the overall performance of CString when a variable strContainerreaches a certain larger size. I assume this is due to the frequent reallocation of memory performed by the statement +=.
strContainer
+=
So, I was curious if there is a way to improve this?
PS1 I do not know the size of the result line in front to pre-select it.
PS2. I have to stick with CString because of the complexity of the project itself. (Or I can't switch to Boost or other newer implementations.)
std::string, += , . L"<" + tag + L">"; , , +=. , , Visual Studio , . Visual Studio , .
std::string
L"<" + tag + L">";
MFC . ( ...) , ATL::CSimpleStringT::PrepareWrite2(int nLength) ( 1,5 , , std::string , ...MFC 1G, 1M.
ATL::CSimpleStringT::PrepareWrite2(int nLength)
, : strContainer 1G, (Preallocate . , .). + +=.
Preallocate
+
Source: https://habr.com/ru/post/1532577/More articles:dart checks if it is building - dartAndroid ART: "Could not find Dex offset for PC offset ..." - androidsocket syscall on linux x86_32 - linux-kernelHow to connect a virtual device / emulator to a Visual Studio Xamarin Android project? - android-emulatorPython sorts the dict by value, creating a list, how to sort it from largest to smallest? - pythonRails 4 and Active Admin: ActiveModel :: ForbiddenAttributesError - ruby-on-rails-4Const gets var, I can't pass it to the template - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1532580/pass-custom-parameters-to-a-dart-application-when-using-pub-serve-to-run-it&usg=ALkJrhhvOQ_mBMdklaEJ0rdLu1Q3u8iWbASUBSTRING_INDEX with multiple delimiters - mysqlHow to combine several matplotlib shapes into one digit? - matplotlibAll Articles