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

The Archive Base Latest Questions

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

I am trying to make an array which holds all the positive integers possible,

  • 0

I am trying to make an array which holds all the positive integers possible, I tried the following code and it allways throws out of memory exception.

private int[] AllIntegers()
{
    int[] all = new int[int.MaxValue];

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

    return all;
}

What I am doing wrong? or this is not possible at all?!

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

    There’s a hard upper limit on .NET object sizes, they cannot be larger than 2 gigabytes. Even on a 64-bit operating system. Your array is well beyond that size.

    On a 32-bit operating system you’ll never get close to that limit, the largest chunk of contiguous virtual memory available is around 650 megabytes, give or take. Only at startup, this goes down hill rapidly. This is a side effect of address space fragmentation, caused by having a mix of code and heaps in the address space. The total amount of memory you can allocate is close to 2 gigabytes, as long as the size of each allocation is small enough. Not something you’d ever want to get close to, random program failure due to OOM is hard to deal with.

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

Sidebar

Related Questions

I am trying to make a c++ program with a class which holds integers
I'm trying to make a function array, which I'm using inside a List.reduce HOF.
I'm trying to build a nested array: First, I make a PlayerItems array which
I'm trying to make an array of objects (animalImages) from a plist file which
I am trying to make a regex which will match the following formats so
I am trying to do a fetch array which pulls out 4 rows and
I'm trying make this code which is from a Dictionary of Arrays (CODE) from
I'm trying to make a dynamic array in C# but I get an annoying
I'm writing some error checking and trying to make use of an boolean array
I'm trying to subclass Array in ruby to make it randomize its elements when

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.