简体   繁体   English

128 GB Ram x64 cpu上的内存不足问题

[英]Out of Memory issue on a 128 GB Ram x64 cpu

I am working on a program where it reads a 312 MB encrypted file into memory stream , decrypts it and copies into destination stream. 我正在开发一个程序,它将312 MB的加密文件读入内存流,对其解密并复制到目标流中。 My program works well with file size of around 120 MB . 我的程序可以很好地运行,文件大小约为120 MB。 I couldn't figure out why it is failing for this ? 我不知道为什么它失败了?

My System info : 64 bit cpu , RAM : 128 GB Also the c# code I built on using Any CPU setting in Configuration Manager. 我的系统信息:64位cpu,RAM:128 GB也是我使用Configuration Manager中的任何CPU设置构建的c#代码。

I wrote a sample program to check where I am getting out of memory and I see that its failing at 512 MB. 我编写了一个示例程序来检查内存不足的地方,我发现它在512 MB时失败。 I do know that the Memory stream requires contigous blocks in the Memory as the RAM is fragmented. 我确实知道随着RAM碎片化,内存流需要内存中的连续块。 But the RAM size is huge here, I tried in multiple machines as well with RAMs of 14 GB, 64GB & 8GB. 但是这里的RAM很大,我也尝试在多台机器上使用14 GB,64GB和8GB的RAM。

Any help is appreciated. 任何帮助表示赞赏。

The sample program I wrote to test the Out of Memory Size : 我编写的用于测试内存不足大小的示例程序:

 const int bufferSize = 4096;
            byte[] buffer = new byte[bufferSize];

            int fileSize = 1000 * 1024 * 1024;

            int total = 0;

            try
            {
                using (MemoryStream memory = new MemoryStream())
                {
                    while (total < fileSize)
                    {
                        memory.Write(buffer, 0, bufferSize);
                        total += bufferSize;
                    }

                }

                Console.WriteLine("No errors");

            }
            catch (OutOfMemoryException)
            {
                Console.WriteLine("OutOfMemory around size : " + (total / (1024m * 1024.0m)) + "MB");
            }

Just running out of Large Object Heap I guess. 我猜只是快用完大对象堆了。 However another approach to solving your problem is to not read the stream into memory - most decrypt algorithms just want a System.IO.Stream - reading it into memory seems a relatively pointless step - just pass the decrypt api your incoming file or network stream instead. 但是,解决问题的另一种方法是不将流读取到内存中-大多数解密算法只需要System.IO.Stream-将其读取到内存中似乎是相对没有意义的步骤-只需将解密api传递给传入文件或网络流即可。

Try disabling the option "Prefer 32 bits" from the project's properties, in "Build" tab, thats works for me. 尝试从项目的属性中禁用“首选32位”选项,在“构建”选项卡中,这对我有用。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM