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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:30:13+00:00 2026-06-15T15:30:13+00:00

I would like to read a large file that has a structure similar to

  • 0

I would like to read a large file that has a structure similar to the following:

        John  10  department
        Hello 14   kjezlkjzlkj
        jhfekh 144 lkjzlkjrzlj
        ........

The problem is I want to minimize the number of I/O access to the disk while reading this file in C++. Is there a way to access the file on Disk, then read a large portion of the file to memory ( that 1 disk access), then read a second large portion of the file ( 2nd disk access…Etc)?

Any help will be appreciated.

  • 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-15T15:30:15+00:00Added an answer on June 15, 2026 at 3:30 pm

    Just create a large buffer and fill it up with one read. Repeat if necessary.

    The streams (stdio) implements this. You can use fopen and then use setbuffer

    EDIT

    It is rather simple

       /* 5MB - Can increase or decrease this to your hearts content */
       #define BUFFER_SIZE 5242880
    
       char buffer[BUFFER_SIZE];
       file = fopen("filename", "r");
       setbuffer(file, buffer, BUFFER_SIZE);
    

    Then use any of the operations to read fscanf, fgets etc.

    EDIT

    Sorry did not notice it was C++

    Here is the code for C++

    #include <iostream>
    #include <fstream>
    using namespace std;
    
    ...
    
    const int BUFFER_SIZE = 5242880;
    
    filebuf fb;
    char buffer[BUFFER_SIZE];
    fb.setbuf(buffer, BUFFER_SIZE);
    fb.open ("test.txt",ios::in);
    istream is(&fb);
    

    Then can use int i; is >> i

    etc

    Happy now Tino Didriksen

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

Sidebar

Related Questions

I would like to read and write the contents of large, raw volume files
I would like to read a little more about the + that is usually
I would like to read a text file and input its contents into an
I would like to read a DICOM file in C#. I don't want to
I would like to read the last 1 megabyte of a MP3 file and
I would like to read a file in R as a table for a
Let's say I have to read from a directory that has many large XML
I have a large XML file (180 megs or so) that has lots of
I want to read in a large ido file that had just under 110,000,000
I've scraped some HTML into a large txt file (~50k lines), and would like

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.