I'm working on a C++ project (using VS2008
) where I will need to load a very large XML file into std::wstring
from a file. Presently the following line reserves memory before the data is loaded:
//std::wstring str;
//size_t ncbDataSz = file size in bytes
str.resize(ncbDataSz / sizeof(WCHAR));
But my current issue is that the resize
method takes somewhat long time for a larger string size (I just tested it with 3GB of data, in a x64
project, on a desktop PC with 12GB
of free RAM and it took about 4-5 seconds to complete.)
So I'm curious, is there's a faster (more optimized) method to resize std::string
? I'm asking for Windows only.