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

  • SEARCH
  • Home
  • 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 7760161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:48:36+00:00 2026-06-01T13:48:36+00:00

I have a function that writes a bitmap string to a browser, which then

  • 0

I have a function that writes a bitmap string to a browser, which then prints it on screen. Currently this works by generating the correct values for each pixel individually and using the write(int fd, char *Buff, int NumBytes) function three times for every pixel, e.g.:

for (i = 0; i < IMAGE_HEIGHT; ++i)
{
    for (j = 0; j < IMAGE_WIDTH; ++j)
    {
        blue = blue();
        green = green();            
        red = red();

        write(soc, &blue, 1);
        write(soc, &green, 1);
        write(soc, &red, 1);
    }
}

I was wanting to optimize the code and figured that calling the write() function so many times is surely costing me something. So, the idea was to store all the values in a character array and then call the write function once:

write (soc, image_array, sizeof(image_array));

but am I going to have problems with the huge arrays (100’s of thousands/millions of elements)? Would just allocating to the heap solve this? I just wanted to make sure I’m not doing anything stupid.

  • 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-06-01T13:48:37+00:00Added an answer on June 1, 2026 at 1:48 pm

    Yes, the multiple writes will hurt you.

    Rather than write each byte individually or allocate the entire thing, I suggest writing to a small buffer (perhaps a few KB) and writing that every time it fills up. That should give you a good performance gain for small memory cost.

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

Sidebar

Related Questions

soooo i have this function that prints one of 5 random texts ON an
I have a function that I use quite frequently, which allows me to write
I have a function that writes file to disk. Using a concurrent server, it
I have a function that writes 3 lines into a empty table like so:
So I have this code in python that writes some values to a Dictionary
I have a function that takes an ostream reference as an argument, writes some
I have a template function in C++ that basically writes values to an XML
I have a multi-threading Python program, and a utility function, writeLog(message) , that writes
I have a function that writes things from a binary tree. When I run
i have a function that writes to a file , how can i using

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.