14345

MaxSize of array in .Net Framework 4.5

As per this website here,the MaxSize of an array can be more than 2GB in the x64 environments and the actual elements it can hold is UInt32.MaxValue.

So,I've made my app.config like :

<configuration> <runtime> <gcAllowVeryLargeObjects enabled="true" /> </runtime> </configuration>

and my array declaration and initialization is :

int idsCount = 999999999; long[] ids = new long[idsCount];

which is much less than the UInt32.MaxValue,but an OutofMemory Exception was thrown. Am I doing any mistake? My Framework version is also 4.5

Answer1:

The basic check-list for this failure:

    <li>

    Watch out for the Visual Studio Hosting process that's enabled by default when you run your program with the debugger attached. It uses a different .config file, yourapp.vshost.exe.config. Quickly eliminate this kind of mishap by disabling the option, Project + Properties, Debug tab.

    </li> <li>

    This can only work when your process runs in 64-bit mode, not the default for a new project. Project + Properties, Build tab, be sure to have the Platform target set to AnyCPU and the "Prefer 32-bit mode" checkbox unticked.

    </li> <li>

    While you are there, click the Application tab and double-check the Target framework setting. Must be 4.5 or higher of course.

    </li> <li>

    The Windows version matters, different versions have different limits for the maximum VM size of a process. Review this MSDN page and locate your Windows version and edition. You'd run into trouble with Windows 7 Home Basic for example, 8 Gigabytes max.

    </li> <li>

    Large allocations in 64-bit mode can fail on a commit failure. Committing is the technical term for reserving space in the operating system's paging file. It acts as the backing-store in case your large array needs to be paged-out to make room for other processes. Pretty much guaranteed to happen if your machine doesn't have well over 8 Gigabytes of RAM available. You might have the size limit set too low or the OS can't grow the paging file quick enough to give you the space you need. Demonstrated well in this blog post by Mark Russinovich.

    </li> </ul>

    Answer2:

    A C# long is 64 bits, or 8 bytes. The array ids is dimensioned for one less than one billion entries, at 8 bytes per entry. That array as defined will use around 8GB.

Recommend

  • Visual Studio 2010 error building, due to missing files
  • Attaching Visual Studio debugger causes high CPU usage and UI thread locks
  • How to Configure Spring Security Rest for Grails 3.x
  • Automatically add links to class source files under a specified directory of another project in Visu
  • How to install ffmpeg for a django app on heroku?
  • Symbolicate Crash Log when App Name Contains Apostrophe and Space (Deployed App)
  • Django - What is the reverse equivalent of cascade?
  • Visual Studio 2008 would not debug
  • How to run .ear file in JBoss 6?
  • CUDA Debugging - VS on windows workstation, GPUs on Linux server?
  • How to add System.Windows dll to Visual Studio 2010 express?
  • How to work with Master Page that is attached to the page via the page's basepage?
  • Adding a new element into the DOM with angularjs does not initiate it
  • Fire callback when selection was made with select2 4.0, and retrieve the value of last selection
  • HighCharts - Show tooltip on column where value is 0 or null
  • RegistryKey.GetSubKeyNames returns names that are not in that subkey!
  • Avoid registering duplicate broadcast receivers in Android
  • How to handle elastic beanstalk deployment so it uploads only changed files
  • jQuery: add elements until a particular height is reached
  • aapt.exe'' finished with non-zero exit value 1
  • Check all values in string[] for length?
  • Function calls are not supported. Consider replacing the function or lambda with a reference to an e
  • Memory error in python- how to use more memory
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Differences in dis-assembled C code of GCC and Borland?
  • Tamper-proof configuration files in .NET?
  • Code in Job's Script Block after Start-Process Does not Execute
  • Algorithm for a smudge tool?
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Running a C# exe file
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Checking variable from a different class in C#