One of my programs has several clients, and each client has its own buffer. In an endless loop, I check to see if any of the clients have any data that will be written to disk. If so, then I do the same and continue.
Now, since the client is writing data that is actually not under my control (the result of some calculations), I need a dynamic buffer. Thus, the pseudocode will look like this:
void Append(int client_id, char *line) {
if(client_id.buffer == NULL) {
buffer = (char*)malloc(BUFFERSIZE * sizeof(char));
} else {
}
}
and another approach is to use a simple message queue. I will add all the messages (lines) to the existing queue and then read them. Is there any other better approach?