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 3305768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:12:31+00:00 2026-05-17T21:12:31+00:00

Sorry if this has been asked before, I haven’t been able to find just

  • 0

Sorry if this has been asked before, I haven’t been able to find just what I am looking for.

I am reading fields from a list and writing them to a block of memory. I could

  • Walk the whole list, find the total needed size, do one malloc and THEN walk the list again and copy each field;
  • Walk the whole list and realloc the block of memory as I write the values;

Right now the first seems the most efficient to me (smallest number of calls). What are the pros and cons of either approach ?

Thank you for your time.

  • 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-17T21:12:32+00:00Added an answer on May 17, 2026 at 9:12 pm

    You’re probably better off allocating a decent amount of space initially, based on what you think is the most likely maximum.

    Then, if you find you need more space, don’t just allocate enough for the extra, allocate a big chunk extra.

    This will minimise the number of re-allocations while still only processing the list once.

    By way of example, initially allocate 100K. If you then find you need more, re-allocate to 200K, even if you only need 101K.

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

Sidebar

Related Questions

Sorry if this has been asked before, but I couldn't find a good example
Sorry if this has been asked before, I did check but couldn't find anything...
Sorry if this question has been asked 100 times before, unfortunately, i haven't found
Sorry if this has been asked before but I've tried searching and can't find
Sorry if this has been asked before, but I couldn't find a solution to
Sorry if this has been asked before, I searched but couldn't find anything. I'm
Sorry if this has been asked before, but I can't find a clear enough
Sorry if this has been asked before (though I can't really find a solution).
Sorry if this has been asked before. I couldn't find a definitive answer. Can
I'm sorry if this has been asked before - but I couldn't find a

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.