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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:59:01+00:00 2026-05-26T08:59:01+00:00

This could possibly appear to be a nasty thing to ask but why do

  • 0

This could possibly appear to be a nasty thing to ask
but why do we have so short limit of number of objects in a list.

i wrote following code to test list size in C#

    List<int> test = new List<int>();            
    long test1 = 0;
    try
    {
        while (true)
        {
            test.Add(1);
            test1++;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(test1 + "   |   " + ex.Message);
    }

and the size of list could only be 134217728

isn’t that unfair 🙁 ??? what is alternate way if i want to add objects even beyond ‘integer’ limits (i mean number of objects > 2^32) ???

  • 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-26T08:59:02+00:00Added an answer on May 26, 2026 at 8:59 am

    A List<int> is backed by an int[]. You will fail as soon as a larger backing array cannot be allocated – and bear in mind that:

    • There’s a 2GB per-object limit in the CLR even in 64 bits (EDIT: as of .NET 4.5, this can be avoided for the 64-bit CLR – see <gcAllowVeryLargeObjects>)
    • The list will try to allocate a backing array which is larger than what it immediately requires, in order to accommodate later Add requests without reallocation.
    • During the reallocation, there has to be enough total memory for both the old and the new arrays.

    Setting the Capacity to a value which will put the backing array near the theoretical limit may get you a higher cutoff point than the natural growth, but that limit will certainly come.

    I would expect a limit of around 229 elements (536,870,912) – I’m slightly surprised you haven’t managed to get beyond 134,217,728. How much memory do you actually have? What version of .NET are you using, and on what architecture? (It’s possible that the per-object limit is 1GB for a 32-bit CLR, I can’t remember for sure.)

    Note that even if the per-object limit wasn’t a problem, as soon as you got above 231 elements you’d have problems addressing those elements directly with List<T>, as the indexer takes an int value.

    Basically, if you want a collection with more than int.MaxValue elements, you’ll need to write your own, probably using multiple backing arrays. You might want to explicitly prohibit removals and arbitrary insertions 🙂

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

Sidebar

Related Questions

Can anybody please explain how this could possibly happen? I am completely aware of
This could quite possibly be the dumbest question ever asked. Our client wants us
What could possibly cause this weird python behaviour? Python 2.6.2 (r262:71600, May 31 2009,
This could be weird, Have you ever come across a blog which you wanted
This could be a little off the ballpark, but a friend asked me about
I suppose this could apply to any dynamic language, but the one I'm using
I have searched through google and SO for possible answers to this question, but
While this could possibly result in a simple yes or no answer I'll go
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
It this possible? How? (Maybe silly question, but I couldn't find answer :( )

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.