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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:55:50+00:00 2026-05-27T14:55:50+00:00

I got to know the maximum object size in C# is 2GB. Also there

  • 0

I got to know the maximum object size in C# is 2GB. Also there is a memory limit for each particular PC and either it is 32 or 64 bit.

In my application I need an array of integers as big as possible. So what I need is to take care of OutOFMemoryException until the biggest possible array can be made!

I end up with the code below:

private int[] AllIntegers()
{
    int[] all;
    int divider = 2;

    try
    {
        all = new int[int.MaxValue];
    }
    catch (OutOfMemoryException)
    {
        all = new int[int.MaxValue / divider];
    }
    //Probably will fail again. how to efficently loop the catch again

    for (int i = 0; i < all.Length; i++)
    {
        all[i] = i;
    }

    return all;
}

the code will also fail, what I am looking for is a proper way of looping untill the array can be made!

  • 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-27T14:55:50+00:00Added an answer on May 27, 2026 at 2:55 pm

    EDIT: I do not like the idea of this, since I think it’s wrong to hold such a large amount of data
    (and an array of all integers?)

    But, here’s what you’re looking for:

        static int[] AllIntegers()
        {
            int iSize = int.MaxValue;
            int[] all;
            int divider = 2;
    
            while (true)
            {
                try
                {
                    all = new int[iSize];
                    break;
                }
                catch (OutOfMemoryException)
                {
                    iSize = iSize/divider ;
                }
            }
    
            //Probably will fail again. how to efficently loop the catch again
    
            for (int i = 0; i < all.Length; i++)
            {
                all[i] = i;
            }
    
            return all;
        }
    

    EDIT2:
    Maybe elaborate us with what you are trying to achieve?

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

Sidebar

Related Questions

I have got around 800 files of maximum 55KB-100KB each where the data is
Does anyone know what the maximum value size you can store in redis? I
I recently got to know about trinidad of Apache MYfaces. For web application i
I do know that ~0 will evaluate the maximum word sized bit 1s (and
I've got a popup div showing on rightclick (I know this breaks expected functionality
Yea i know i'm way behind times but what i've got here is a
I would like to know how the Cocoa Framework got its name. I know
Hi I got something wrong in my code and I don't know why My
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I know I've had this problem before so I'm really frustrated. I've got the

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.