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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:50:16+00:00 2026-05-17T19:50:16+00:00

Basic c++ question here. I’m trying to read a large file on Windows 7

  • 0

Basic c++ question here. I’m trying to read a large file on Windows 7 Pro. C++ compiler is Visual Studio 2010. (ver 16.0). I’m finding that the program runs about 5 times slower on Windows 7 than one on a virtual machine running Ubuntu on the same box. Ubuntu version 10.04 using gcc 4.4.3. The file is rather large ~900MB. The code in question can be narrowed to the following snippet. Any clues on Windows specific tuning to read files faster? The file is about 17 million lines and it takes about 13 seconds on Windows 7 and about 2.3 seconds on Ubuntu (which is a VM on the same Windows 7 box). I’m using /O2 flags on visual c++ and -O3 on Ubuntu/gcc 4.4.3

Thanks

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
    const char* test_file_path = argv[1];
    ifstream ifs(test_file_path);

    if (!ifs.is_open()) {
    cout << "Could not open " << test_file_path << endl;
    return 0;
    }

    unsigned long line_count = 1;
    unsigned long sum = 0;
    string line;
    // Go through all the lines in the file
    while (getline(ifs, line)) {
        line_count++;
    }
    cout << line_count << '\n';
    return 0;
}

Edit: Tried boost memory mapped file suggestion by Anders and time dropped to 1.2 seconds. Looks like Ubuntu sort of defaults to this while you need to be explicit on Windows. Thanks Anders.

  • 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-17T19:50:16+00:00Added an answer on May 17, 2026 at 7:50 pm

    If you are concerned with performance I would recommend to step out of the C++ world and into Win32 API file handling (e.g. memory mapped files, boost has a library for that).

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

Sidebar

Related Questions

This must be a really basic question: I am trying to use Matplotlib. Here's
Basic question here: I'm sending emails using the default SmtpClient of the .NET framework
Rather basic question here guys. Basically I have code like this: public SuperPanel() {
Really basic question here. So I'm told that a dot . matches any character
Real basic CI question here, which I cant find anything on in the documentation.
( insert really basic question disclaimer here ) More specifically, I have the following
I'm sure that this is an extremely basic question but here goes anyway! I
Basic question here (I think), I was hoping someone could point me in the
Basic question here, can I put String variables into a position in a string
I've got a basic PIVOT-question here that probably won't cause you gurus any trouble:

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.