Manual allocation of socket memory.

This commit is contained in:
Bartosz Taudul 2017-10-18 19:49:17 +02:00
parent fc94378e0c
commit 51013dc0e6
4 changed files with 15 additions and 6 deletions

View File

@ -101,6 +101,7 @@ Profiler::Profiler()
, m_mainThread( GetThreadHandle() )
, m_epoch( std::chrono::duration_cast<std::chrono::seconds>( 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;
}

View File

@ -185,7 +185,7 @@ private:
uint64_t m_mainThread;
uint64_t m_epoch;
std::atomic<bool> m_shutdown;
std::unique_ptr<Socket> m_sock;
Socket* m_sock;
LZ4_stream_t* m_stream;
char* m_buffer;

View File

@ -1,9 +1,11 @@
#include <assert.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#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<Socket> ListenSocket::Accept()
Socket* ListenSocket::Accept()
{
struct sockaddr_storage remote;
socklen_t sz = sizeof( remote );
@ -249,7 +251,9 @@ std::unique_ptr<Socket> ListenSocket::Accept()
}
else
{
return std::make_unique<Socket>( sock );
auto ptr = (Socket*)tracy_malloc( sizeof( Socket ) );
new(ptr) Socket( sock );
return ptr;
}
}
else

View File

@ -1,8 +1,6 @@
#ifndef __TRACYSOCKET_HPP__
#define __TRACYSOCKET_HPP__
#include <memory>
struct timeval;
namespace tracy
@ -40,7 +38,7 @@ public:
~ListenSocket();
bool Listen( const char* port, int backlog );
std::unique_ptr<Socket> Accept();
Socket* Accept();
void Close();
ListenSocket( const ListenSocket& ) = delete;