avoid allocating memory in time critical routines

This commit is contained in:
Volker Fischer 2014-01-23 20:33:55 +00:00
parent 676b5d9b97
commit 4b83fa6fe0
2 changed files with 5 additions and 4 deletions

View File

@ -43,6 +43,7 @@ void CSocket::Init ( const quint16 iPortNumber )
// incremented port numbers // incremented port numbers
quint16 iClientPortIncrement = 10; // start value: port nubmer plus ten quint16 iClientPortIncrement = 10; // start value: port nubmer plus ten
bSuccess = false; // initialization for while loop bSuccess = false; // initialization for while loop
while ( !bSuccess && while ( !bSuccess &&
( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) ) ( iClientPortIncrement <= NUM_SOCKET_PORTS_TO_TRY ) )
{ {
@ -136,9 +137,6 @@ void CSocket::OnDataReceived()
{ {
while ( SocketDevice.hasPendingDatagrams() ) while ( SocketDevice.hasPendingDatagrams() )
{ {
QHostAddress SenderAddress;
quint16 SenderPort;
// read block from network interface and query address of sender // read block from network interface and query address of sender
const int iNumBytesRead = const int iNumBytesRead =
SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0], SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
@ -153,7 +151,8 @@ void CSocket::OnDataReceived()
} }
// convert address of client // convert address of client
const CHostAddress RecHostAddr ( SenderAddress, SenderPort ); RecHostAddr.InetAddr = SenderAddress;
RecHostAddr.iPort = SenderPort;
if ( bIsClient ) if ( bIsClient )
{ {

View File

@ -80,6 +80,8 @@ protected:
CVector<uint8_t> vecbyRecBuf; CVector<uint8_t> vecbyRecBuf;
CHostAddress RecHostAddr; CHostAddress RecHostAddr;
QHostAddress SenderAddress;
quint16 SenderPort;
CChannel* pChannel; // for client CChannel* pChannel; // for client
CServer* pServer; // for server CServer* pServer; // for server