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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:24+00:00 2026-05-26T11:42:24+00:00

In my C++ project, I have a large, GB binary file on disk that

  • 0

In my C++ project, I have a large, GB binary file on disk that I read into memory for read-only calculations.

My current C++ implementation involves reading the entire chunk into memory once and then spawning threads to read from the chunk in order to do various calculations (mutex-free and runs quickly). Technically, each thread really only needs a small part of the file at a time, so in the future, I may change this implementation to use mmap(), especially if the file gets too big. I’ve noticed this gommap lib so I think I should be covered going forward.

What approach should I take to translate my current C++ threading model (one large chunk of read-only memory) into a go threading model, keeping run-time efficiency in mind?

goroutines? alternatives?

  • 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-26T11:42:25+00:00Added an answer on May 26, 2026 at 11:42 am

    I’m sure this answer will cop a lot of heat but here goes:

    You won’t get reduced running time by switching to Go, especially if your code is already mutex free. Go doesn’t guarantee efficient balancing of goroutines, and will not currently make best use of the available cores. The generated code is slower than C++. Go’s current strengths are in clean abstractions, and concurrency, not parallelism.

    Reading the entire file up front isn’t particular efficient if you then have to go and backtrack through memory. Parts of the file you won’t use again until much later will be dropped from the cache, only to be reloaded again later. You should consider memory mapping if your platform will allow it, so that pages are loaded from disk as they’re required.

    If there is any intense inter-routine communication, or dependencies between the data you should try to make the algorithm single threaded. It’s difficult to say without knowing more about the routines you’re applying to the data, but it does sound possible that you’ve pulled out threads prematurely in the hope to get a magic performance boost.

    If you’re unable to rely on memory mapping due to file size, or other platform constraints, you should consider making use of the pread call, thereby reusing a single file descriptor, and only reading as required.

    As always, the following rule applies to optimization. You must profile. You must check that changes you make from a working solution, are improving things. Very often you’ll find that memory mapping, threading and other shenanigans have no noticeable effect on performance whatsoever. It’s also an uphill battle if you’re switching away from C or C++.

    Also, you should spawn goroutines to handle each part of the file, and reduce the results of the calculations through a channel. Make sure to set GOMAXPROCS to an appropriate value.

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

Sidebar

Related Questions

In my current project we have a large repository of content that was originally
I have a large project where we have 2-3 dll projects that are converted
I have a large project but I need only some folders in my svn
I have a large GUI project that I'd like to port to Linux. What
I have this large C++ project that I need to build on a platform
We have a large MS Access project that requires GUI functionality that is difficult
I have a large binary file to parse, and i am not sure about
I'm going to be starting a project soon that requires support for large-ish binary
I have a large project that uses the Qt framework and am trying to
I have a large vb.net web project that I am trying to updgrade to

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.