im implementing a tcp/ip service in c++. what happen is that the server will receive data and each data may contain 1 or more messages. the server is only allow to receive a max of e.g 100 bytes of data per round. so in scenario 1, if a message is of 120 bytes, it will be split into 2 data. so i create a global static char tmpbuffer[100] temporary. upon receviving the data, i check the msg header for the total message size. if its more than 100 bytes, i store the first 100 bytes into tmpbuffer. it will wait for the 2nd loop where the next 100 bytes of data will come.this 100 bytes will contain the remaining 20 bytes which i wanna concat to the tmpbuffer.
however the problem here is that tmpbuffer size increases dynamically. lets assume that this function will cater for messages much bigger than just 120 bytes. it could be 1000 bytes, thus the message will be split into 10 data each of 100 bytes. by using char only, can i increase the tmpbuffer size dynamically? that means gloablly i set,
static tmpbuffer[100]. in the function, once i know the total message size from the msg header, how can i increase the tmpbuffer size.
Use a
std::vectorinstead. Will save you soooo much hassle.