You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/11/07 12:10:53 UTC

[GitHub] [logging-log4cxx] rm5248 commented on a diff in pull request #148: Reduce std::ostream logging overhead

rm5248 commented on code in PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148#discussion_r1015347242


##########
src/main/cpp/messagebuffer.cpp:
##########
@@ -149,10 +118,14 @@ CharMessageBuffer& CharMessageBuffer::operator<<(const char msg)
 
 CharMessageBuffer::operator std::basic_ostream<char>& ()
 {
-	if (m_priv->stream == 0)
+	if (!m_priv->stream)
 	{
+#if LOG4CXX_HAS_THREAD_LOCAL
+		thread_local static std::basic_ostringstream<char> sStream;
+		m_priv->stream = &sStream;
+#else
 		m_priv->stream = new std::basic_ostringstream<char>();
-
+#endif

Review Comment:
   At this point I'm not aware of any compiler that supports C++11 but not `thread_local`, would it make sense to simply make `m_priv->stream` a `thread_local` variable instead of holding a pointer?  I could be wrong here, but it looks like if two threads are logging at the same time they could both get the same `ostringstream`, thus defeating the purpose of the `thread_local`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org