Commit 79f17d17 authored by Julien Gamba's avatar Julien Gamba

Switched RECV_DATA to vector to enhance perfomance

parent c76cc7b8
...@@ -54,10 +54,11 @@ void * CComUDPServer::UDP_server_thread(void *parm) { ...@@ -54,10 +54,11 @@ void * CComUDPServer::UDP_server_thread(void *parm) {
printf(" Received individual from %s:%d\n", inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port)); printf(" Received individual from %s:%d\n", inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port));
pthread_mutex_lock(&server_mutex); pthread_mutex_lock(&server_mutex);
/*process received data */ /*process received data */
memmove(p->data[(*p->nb_data)].data,buffer,sizeof(char)*MAXINDSIZE); RECV_DATA buffer_copy = RECV_DATA();
(*p->nb_data)++; memmove(buffer_copy.data,buffer,sizeof(char)*MAXINDSIZE);
// printf("address %p\n",(p->data)); // printf("address %p\n",(p->data));
p->data = (RECV_DATA*)realloc(p->data,sizeof(RECV_DATA)*((*p->nb_data)+1)); p->data.push_back(buffer_copy);
(*p->nb_data)++;
// printf("address %p\n",(p->data)); // printf("address %p\n",(p->data));
pthread_mutex_unlock(&server_mutex); pthread_mutex_unlock(&server_mutex);
/*reset receiving buffer*/ /*reset receiving buffer*/
...@@ -71,7 +72,7 @@ CComUDPServer::CComUDPServer(unsigned short port,int dg) { ...@@ -71,7 +72,7 @@ CComUDPServer::CComUDPServer(unsigned short port,int dg) {
struct sockaddr_in ServAddr; /* Local address */ struct sockaddr_in ServAddr; /* Local address */
debug = dg; debug = dg;
this->nb_data = 0; this->nb_data = 0;
this->data = (RECV_DATA*)calloc(1,sizeof(RECV_DATA)); this->data.assign(sizeof(RECV_DATA),RECV_DATA());
#ifdef WIN32 #ifdef WIN32
WSADATA wsadata; WSADATA wsadata;
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) { if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <omp.h> #include <omp.h>
#endif #endif
#include <string> #include <string>
#include <vector>
#define _MULTI_THREADED #define _MULTI_THREADED
#define MAXINDSIZE 50000 /*maximum size of an individual in number of characters*/ #define MAXINDSIZE 50000 /*maximum size of an individual in number of characters*/
...@@ -40,7 +41,7 @@ typedef struct { ...@@ -40,7 +41,7 @@ typedef struct {
int Socket; /* Socket descriptor for server */ int Socket; /* Socket descriptor for server */
struct sockaddr_in ServAddr; /* Local address */ struct sockaddr_in ServAddr; /* Local address */
int debug; int debug;
RECV_DATA *data; std::vector<RECV_DATA> data;
int *nb_data; int *nb_data;
}UDP_server_thread_parm_t; }UDP_server_thread_parm_t;
...@@ -48,7 +49,7 @@ class CComUDPServer { ...@@ -48,7 +49,7 @@ class CComUDPServer {
public: public:
int debug; int debug;
RECV_DATA *data; std::vector<RECV_DATA> data;
int nb_data; int nb_data;
UDP_server_thread_parm_t *parm; UDP_server_thread_parm_t *parm;
CComUDPServer(unsigned short port, int dg); CComUDPServer(unsigned short port, int dg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment