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

  • Home
  • SEARCH
  • 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 8574481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:29:03+00:00 2026-06-11T19:29:03+00:00

Here is the situation: I have list which store strings which are actually numbers

  • 0

Here is the situation:
I have list which store strings which are actually numbers and can become pretty big (hundreds of millions of items).
I store the numbers as string because there is a option to display some additional information which is text.

Because this takes a lot of memory to store I decided that I will store only a maximum of 5 million items. (this will only take about 250-300mb).

The list is filled by the output of a calculation. If a number is found it will be added to the list, this number is always bigger than the existing items.

When the list reached 5 mil I want to remove the first item and add the new item to the list.

like:

    // Why is this so freaking slow???
    if (_result.Count == 5000000)
        _result.RemoveAt(0);
    _result.Add(result);

As you can read in the comment, this is very, very, very slow. It just cut down my performance by 15 times. Where it took 2 minutes it now takes about 30.

I tried a few things with linq like .Skip(1).ToList but that will recreate the list and is therefore even more slow.

The list must stay in the right order, so overwriting by index is not an option (unless you could explain a nice work around).

My question:
Is there any decent way to do this?

I really need the performance here since it may need to check up about 10000000000 numbers. This may take a day ofcourse, but a month is a bit too much :(.

Need additional information, feel free to ask, I’ll be happy to supply.

Solution:
This performs O(1)

    // Set the _result
    Queue<object> _result = new Queue<object>(5000000);

    /// Inside the method
    // If the count has reach it's max, dequeue the first item
    if (_result.Count == 5000000)
        _result.Dequeue();
    _result.Enqueue(result);
  • 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-11T19:29:04+00:00Added an answer on June 11, 2026 at 7:29 pm

    Do you ever reorder items? If you don’t, a circular queue would work quite well.

    System.Collections.Generic.Queue is one, I just double checked.

    To expand on the benefits of a Queue, this is the RemoveAt implementation (roughly):

    for (int i = 1; i < count; i++)
        items[i-1] = items[i];
    count--;
    

    Because list[0] is always the first item, you have to move everything to remove the first item.

    In contrast, a queue tracks the first item separately. This changes the above code to this:

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

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
Here's the situation I have a webpage which has one drop down called prefer.
Here's the situation: I have a web application which response to a request for
Here is my situation: I have a controller action called OrderFromCategory which fills a
Ok, here's the situation. I use Doctrine 2 and PHPUnit. I have a list
I need some help here. Here is my situation: I have a binding list
Here's the situation. I have two sets of data. One is a list of
Here is the situation : we have to offer a customer with a web-based
here's the situation: I have a where in every cell all the area has
Here is my situation: I have a C project linking with many libraries (I

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.