兩種方法在Visual Studio Win32控制平台程序中使用超過4G的內存(以Visual Sutdio 2013為例)
如果你的程序運行中由於申請大空間而拋出了bad alloc異常,那這篇文章提出的兩個方法將對你有些幫助。
捕獲異常的方法很簡單: try { your code...} catch (exception e) {cerr << e.what() << endl;}
1: 啟用大地址
在解決方案資源管理器中右鍵點擊項目->屬性,選擇連接器->系統->啟用大地址。(不超過4G,由於還有系統,所以最多也就能申請3.x G)
2、64bit 系統可以選擇X64平台突破內存限制
32bit系統的有4GB內存限制,因為地址是32位使得這個地址所能代表的內存空間也就 2^32 byte = 4 GB。
如果你的系統是64bit則沒有4GB的限制,Visual Studio雖然只有32bit版的,但是它提供了64bit的平台編譯,我們所要做的只是選擇程序的編譯平台是X64。
方法如下: 依舊調出屬性頁,右上角配置管理器,活動解決方案平台->新建,新窗口選擇X64平台,之后順着它操作就行了。
添加完的頁面如下,關閉即可。
(有條件就升級64bit系統吧。)
author: YuManZi
when catching bad-alloc exception, following two way may help you, if you are developing visual studio win32 console project.
Two ways to use large main memory for Microsoft Visual Studio Win32 Console Project
1: use /LARGEADDRESSAWARE
right click your project in Solution Explorer->Properties, Linker->System, select /LARGEADDRESSAWARE in use large address.
2: change platform to X64(64 bit), instead of ARM(32bit)
As we all known, 32 bit system has a memory limitation of 4GB(=2^32 bytes), so we can change to X64 platform for those 64 bit system users to avoid such a memory limitation.
still call the Properties window for your project, click Active Solution Platform, New, select X64 instean ARM for new platform.