Allocating more than 1,000 MB of memory in 32-bit .NET process

前端 未结 6 1816
眼角桃花
眼角桃花 2020-12-01 08:10

I am wondering why I\'m not able to allocate more that 1,000 MB of memory in my 32-bit .NET process. The following mini application throws an OutOfMemoryException after havi

6条回答
  •  青春惊慌失措
    2020-12-01 08:50

    I am truly sorry if I didn't get your point but:

    static void Main(string[] args)
    {
        ArrayList list = new ArrayList();
        int i = 0;
        while (true)
        {
            using(byte newBt = new byte[1024 * 1024 * 10])
            {
                list.Add(newBt); // 10 MB
                i += 10;
                Console.WriteLine(i);
            }
        }
    }
    

    Have you tried the using method? And this might be a stupid question but why did you create an eternal loop? O if you try the code strip the symbols >.> xD.

    Source: http://msdn.microsoft.com/en-us/library/yh598w02(v=vs.80).aspx

提交回复
热议问题