i need a std::string of size
bytes, after constructing it i am going to write to every byte in that string prior to reading from it, thus null-initializing the string is a waste of cpu, this works:
std::string s(size,0);
but it's just slightly wasteful, it's basically like using calloc()
when all i need is malloc()
, so the question is, how do i construct a string of X uninitialized bytes?
(using reserve()+push is not an option because im giving the string to a C-api taking char*,size
to do the actual initialization)
edit: this thread seems to about the same issue/related (but with vectors instead of strings): Value-Initialized Objects in C++11 and std::vector constructor