diff --git a/example/example.cpp b/example/example.cpp index 07d6be29..ce4bab88 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -18,7 +18,10 @@ using namespace utils; int main(int argc, char* argv[]) { - if(argc || argv) {}; + + if(argc || argv) {}; + std::string s; + cout << "STRING cap: " << format(s.capacity()) << endl; auto fsink = std::make_shared("log", "txt", 1024*1024*50 , 5, 0); //auto fsink = std::make_shared("simplelog", "txt"); diff --git a/include/c11log/details/fast_oss.h b/include/c11log/details/fast_oss.h index 9cfb7371..b02ff4ac 100644 --- a/include/c11log/details/fast_oss.h +++ b/include/c11log/details/fast_oss.h @@ -40,6 +40,12 @@ protected: virtual std::streamsize xsputn(const char_type* s, std::streamsize count) override { + + auto ssize = _str.size(); + auto cap_left = _str.capacity() - ssize; + if(cap_left < static_cast(count)) + _str.reserve(ssize + count + 128); + _str.append(s, static_cast(count)); return count; }