NET Framework 4.5 new feature (3) 64-bit platform supports arrays larger than 2 GB, framework4.5

Source: Internet
Author: User

NET Framework 4.5 new feature (3) 64-bit platform supports arrays larger than 2 GB, framework4.5

 

The 64-bit platform. NET Framework array cannot exceed 2 GB. This restriction is a big problem for staff who need to use large matrices and vector computing.

 

A System. OutOfMemoryException is often thrown when you use large matrices and vector computing, no matter how large the RAM capacity is, as shown in:

 

 

Reference Program

 class Program    {        private static void Main(string[] args)        {            int arrysize = 150000000;            var large=new decimal[arrysize];            Console.ReadLine();        }    }

 

Fortunately. NET Framework 4.5 introduces a Configuration Attribute in runtime mode, so that the total size of the array is greater than 2 GB 64-bit applications.

You only need to enable the gcAllowVeryLargeObjects element to control the behavior of. NET garbage-collection system.

Reference template

<?xml version="1.0" encoding="utf-8" ?><configuration>    <startup>         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />    </startup>    <runtime>      <gcAllowVeryLargeObjects enabled="true" />     </runtime></configuration>

You can see that the result does not throw an exception and can run normally, as shown below:

 

This method makes better use of available memory when using a huge array on a 64-bit platform.

You can combine this setting with garbage-collection system to improve it. However, the maximum number of elements in the. NET Framework 4.5 and. NET Framework 4.0 arrays is the same.

 

 

 

 




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.