Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 585475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:00:24+00:00 2026-05-13T15:00:24+00:00

In one of my programs, there are multiple clients and each client has its

  • 0

In one of my programs, there are multiple clients and each client has its own buffer. In an infinite loop, I check if any of the client has any data to be written to disk. If it does, then I do the same and continue.

Now, because the client writes data that is not really in my control (result of some computations), I need a dynamic buffer. So the pseudo code would look like this:

//If data is ready
//Append(client_id, line)

void Append(int client_id, char *line) {
   if(client_id.buffer == NULL) {
      buffer = (char*)malloc(BUFFERSIZE * sizeof(char));
      //Copy line into buffer
   } else {
      //Realloc the buffer if insufficient space and append this
      //line to the existing buffer
   }
}

or the other approach would be to use a simple message queue. I would keep adding whatever messages (strings) to an existing queue and then read them off. Is there some other better approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:00:25+00:00Added an answer on May 13, 2026 at 3:00 pm

    I might not have fully understood your architecture, but my understanding is that a client calls you by passing it’s ID and a char * and wants you to write it to disk.

    Is there a reason you have to copy the original buffer? By doing that, you have everything in memory twice and an opportunity to mess up memory management. If possible, just work off of the original buffer.

    Is there some threading happening here? If this is all single threaded (from the point of view of this “server” code at least… one thread to poll and write results), you don’t really need a FIFO since things will just happen in the order you poll clients. If there is a thread (or multiple ones) to poll clients and a separate thread to write the results, a FIFO is a great way to organize thread communication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$0 is the variable for the top level Ruby program, but is there one
One of our programs is sometimes getting an OutOfMemory error on one user's machine,
one of the programs I'm developing at work is reading the registry to figure
One of our programs is erroring out because a stored procedure was created with
Greetings, currently I am refactoring one of my programs, and I found an interesting
One thing that annoys me when debugging programs in Visual Studio (2005 in my
I have seen many programs consisting of structures like the one below typedef struct
Just wondering what little scripts/programs people here have written that helps one with his
I've been looking into different web statistics programs for my site, and one promising
I write a lot of short throwaway programs, and one of the things I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.