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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:58:38+00:00 2026-06-10T09:58:38+00:00

I am trying to parse large strings that I have loaded into memory from

  • 0

I am trying to parse large strings that I have loaded into memory from a file. I am parsing DNA sequences (stored as string) with a sliding window of variable length. The problem is that the strings are so large that it takes a very long time to iterate through them. I don’t know if it is even possible but is it possible to speed this up somehow?

I mean I expected I/O to dominate my application so I shift my line by line reading to reading the whole file into memory at once, but after testing my code I found it spends most of the time in a loop like this:

size_t currentCharNumber = 0;
int16_t windowSize = 50;
//seq is a string of length 249250621
while(seq.length() - currentLinePos < windowSize)
{
   string temp = seq.substr(currentLinePos, windowSize);
   //do stuff to temp
   ++currentLinePos;
}

It only take seconds for loading the sequence into memory from a file but takes ~30 mins to parse the sequence (even after commenting out the processing below the substr() call). Is there something I’m missing that is adding a lot of overhead or is it probably due to the size of my data?

Would it be helpful to mention that I can ignore substrings with characters other that ATCG? I mean I do this filtering in my code but only after I get the strings from substr.

This is my first time posting, and my C++ is a little rusty. Any feedback would be greatly 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-10T09:58:39+00:00Added an answer on June 10, 2026 at 9:58 am

    You might want to consider switching from using a string to hold your sliding window to using a std::deque<char>. The deque type is optimized for inserting and removing values at either end, and is therefore a good candidate here. You can start by loading the first 50 characters into the deque, and then can adjust your loop like this:

    /* Initialize the window to the first windowSize characters. */
    std::deque<char> window(seq.begin(), seq.begin() + windowSize);
    
    /* Repeatedly process each window. */
    for (size_t i = windowSize; i < seq.length(); ++i) {
        /* Do something to window */
    
        /* Drop the first character from the window, then add the next character
         * of the sequence.
         */
        window.pop_front();
        window.push_back(seq[i]);     
    }
    

    This makes the time to construct each window O(1) instead of O(k), where k is the number of characters in the window. This could dramatically decrease the runtime, since the number of characters in your window is pretty large.

    Hope this helps!

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

Sidebar

Related Questions

I'm trying to parse a large csv file and perform some operations on that
I'm trying to parse a large number of short strings into some logical parts.
I am trying to parse a rather large json file, and I am beginning
I have the following JSON that I want to parse into C#. I am
I have a text file that lists the names of a large number of
I have a large (1MB+) XML file, and I'm trying to create an object
I have written a generic CSV file reader that I'm trying to use to
I am trying to parse a large XML file using JavaScript. Looking online, it
I have a string like this that I need to parse into a 2D
I have memory mapped a large formatted (text) file containing one integer per line

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.