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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:07:26+00:00 2026-05-18T03:07:26+00:00

I have memory mapped a large formatted (text) file containing one integer per line

  • 0

I have memory mapped a large formatted (text) file containing one integer per line like so:

123
345
34324
3232
...

So, I have a pointer to the memory at the first byte and also a pointer to the memory at the last byte. I am trying to read all those integers into an array as fast as possible. Initially I created a specialized std::streambuf class to work with std::istream to read from that memory but it seem to be relatively slow.

Do you have any suggestion on how to efficiently parse a string like “1231232\r\n123123\r\n123\r\n1231\r\n2387897…” into an array {1231232,123123,1231,231,2387897,…} ?

The number of integers in the file is not known beforehand.

  • 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-18T03:07:27+00:00Added an answer on May 18, 2026 at 3:07 am
    std::vector<int> array;
    char * p = ...; // start of memory mapped block
    while ( not end of memory block )
    {
        array.push_back(static_cast<int>(strtol(p, &p, 10)));
        while (not end of memory block && !isdigit(*p))
            ++p;
    }
    

    This code is a little unsafe since there’s no guarantee that strtol will stop at the end of the memory mapped block, but it’s a start. Should go very fast even with additional checking added.

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

Sidebar

Related Questions

I have a byte array in memory, read from a file. I would like
I have a memory buffer corresponding to my screen resolution (1280x800 at 24-bits-per-pixel) that
I have a tree structure in memory that I would like to render in
.Net 4 will have a brilliant support for memory mapped files. The two main
The CreateFileMapping function returns a pointer to a memory mapped file, and I want
I have a very simple class that opens a file and creates a memory
Is it ever acceptable to have a memory leak in your C or C++
I am using Borland Builder C++. I have a memory leak and I know
Admittedly I don't get it. Say you have a memory with a memory word
I have a .z80 memory dump. How do I reverse engineer it? What do

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.