From 51013dc0e604e4f04b92504b7117bc0f654ceedb Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 18 Oct 2017 19:49:17 +0200 Subject: [PATCH] Manual allocation of socket memory. --- client/TracyProfiler.cpp | 7 +++++++ client/TracyProfiler.hpp | 2 +- common/TracySocket.cpp | 8 ++++++-- common/TracySocket.hpp | 4 +--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 0615cf6c..07e2bc20 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -101,6 +101,7 @@ Profiler::Profiler() , m_mainThread( GetThreadHandle() ) , m_epoch( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() ) , m_shutdown( false ) + , m_sock( nullptr ) , m_stream( LZ4_createStream() ) , m_buffer( (char*)tracy_malloc( TargetFrameSize*3 ) ) , m_bufferOffset( 0 ) @@ -134,6 +135,12 @@ Profiler::~Profiler() tracy_free( m_buffer ); LZ4_freeStream( m_stream ); + if( m_sock ) + { + m_sock->~Socket(); + tracy_free( m_sock ); + } + assert( s_instance ); s_instance = nullptr; } diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index 44a92d20..24e8f30c 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -185,7 +185,7 @@ private: uint64_t m_mainThread; uint64_t m_epoch; std::atomic m_shutdown; - std::unique_ptr m_sock; + Socket* m_sock; LZ4_stream_t* m_stream; char* m_buffer; diff --git a/common/TracySocket.cpp b/common/TracySocket.cpp index 3ded5bdc..f82db783 100644 --- a/common/TracySocket.cpp +++ b/common/TracySocket.cpp @@ -1,9 +1,11 @@ #include +#include #include #include #include #include +#include "TracyAlloc.hpp" #include "TracySocket.hpp" #ifdef _MSC_VER @@ -226,7 +228,7 @@ bool ListenSocket::Listen( const char* port, int backlog ) return true; } -std::unique_ptr ListenSocket::Accept() +Socket* ListenSocket::Accept() { struct sockaddr_storage remote; socklen_t sz = sizeof( remote ); @@ -249,7 +251,9 @@ std::unique_ptr ListenSocket::Accept() } else { - return std::make_unique( sock ); + auto ptr = (Socket*)tracy_malloc( sizeof( Socket ) ); + new(ptr) Socket( sock ); + return ptr; } } else diff --git a/common/TracySocket.hpp b/common/TracySocket.hpp index e1070cf1..4675620b 100644 --- a/common/TracySocket.hpp +++ b/common/TracySocket.hpp @@ -1,8 +1,6 @@ #ifndef __TRACYSOCKET_HPP__ #define __TRACYSOCKET_HPP__ -#include - struct timeval; namespace tracy @@ -40,7 +38,7 @@ public: ~ListenSocket(); bool Listen( const char* port, int backlog ); - std::unique_ptr Accept(); + Socket* Accept(); void Close(); ListenSocket( const ListenSocket& ) = delete;