C#需要怎样才能使用更多内存?

深圳峰哥 2013-07-15 04:11:05
如下程序,运行时内存不足,请问该怎么做才能使得程序运行正确:
64位机器,实际内存很丰富,是不是需要在App.config里怎么配置一下?谢谢了!
快速结贴!!!
class Program
{
static void Main(string[] args)
{
byte[] b1 = new byte[1024 * 1024 * 1024];
byte[] b2 = new byte[1024 * 1024 * 1024];
byte[] b3 = new byte[1024 * 1024 * 1024];
byte[] b4 = new byte[1024 * 1024 * 1024];
byte[] b5 = new byte[1024 * 1024 * 1024];
byte[] b6 = new byte[1024 * 1024 * 1024];
byte[] b7 = new byte[1024 * 1024 * 1024];
byte[] b8 = new byte[1024 * 1024 * 1024];
byte[] b9 = new byte[1024 * 1024 * 1024];
byte[] b10 = new byte[1024 * 1024 * 1024];
}
}
...全文
257 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
深圳峰哥 2013-07-15
  • 打赏
  • 举报
回复
OK,搞定,只要在项目属性->生成->目标平台中选中x64,就可以输出4个1G OK. 结贴,散分,见者有份
深圳峰哥 2013-07-15
  • 打赏
  • 举报
回复
按理说64位的系统和环境直接new就可以了啊
深圳峰哥 2013-07-15
  • 打赏
  • 举报
回复
程序的确需要用到2G以上,用.net是为了快速开发,要不就用C++了
hudsonhuang 2013-07-15
  • 打赏
  • 举报
回复
分开几个程序,分布式计算不好么?
宸瑞-疾风 2013-07-15
  • 打赏
  • 举报
回复
用完释放掉就行阿。程序一般要避免使用内存过多。
本拉灯 2013-07-15
  • 打赏
  • 举报
回复
http://www.cnblogs.com/eaglet/archive/2008/11/06/1328061.html
深圳峰哥 2013-07-15
  • 打赏
  • 举报
回复
感谢回复! 把代码改了,还是只能打印出1个1G OK。没有一个简单的可以用到2G以上内存的例子么? 如果没有的话,晚饭后再研究那个BigArray吧 static void Main(string[] args) { try { long[] b1 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); long[] b2 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); long[] b3 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); long[] b4 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); long[] b5 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); long[] b6 = new long[1024 * 1024 * 1024 / 8]; Console.WriteLine("1G OK"); } catch (Exception e) { Console.WriteLine(e.Message); } }
effun 2013-07-15
  • 打赏
  • 举报
回复
要用到这么大的内存的程序一定不正常,是否程序的设计思路有问题?
threenewbee 2013-07-15
  • 打赏
  • 举报
回复
引用 2 楼 budan 的回复:
楼上给的链接,第一段就是: I’ve received a number of queries as to why the 64-bit version of the 2.0 .Net runtime still has array maximum sizes limited to 2GB. Given that it seems to be a hot topic of late I figured a little background and a discussion of the options to get around this limitation was in order. 大概就是说:.net只给一个进程最多2G内存?这样的话用不用BigArray<T>意义不大。
why the 64-bit version of the 2.0 .Net runtime still has array maximum sizes limited to 2GB 是数组大小,不是进程内存大小。
深圳峰哥 2013-07-15
  • 打赏
  • 举报
回复
楼上给的链接,第一段就是: I’ve received a number of queries as to why the 64-bit version of the 2.0 .Net runtime still has array maximum sizes limited to 2GB. Given that it seems to be a hot topic of late I figured a little background and a discussion of the options to get around this limitation was in order. 大概就是说:.net只给一个进程最多2G内存?这样的话用不用BigArray<T>意义不大。
threenewbee 2013-07-15
  • 打赏
  • 举报
回复
这代码用到10GB内存了。如果你要使用2GB以上的数组,试试看BigArray<T> http://blogs.msdn.com/b/joshwil/archive/2005/08/10/450202.aspx

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧