Re: [問題] 要如何向 physical memory 要 更多的記 …
※ 引述《tedd15550325 (天行者)》之銘言:
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: windows 7 64-bit, VS C++ 2008
: 如題
: 目前遇到的窘境
: 就是記憶體已經被我malloc到不夠了(回傳NULL)
: 測試了一下
: 由工作管理員顯示,program 大概使用到了 2G 就不行了
: google了一下
: 記憶體有分為 physical mem. 和 virtual mem.
: 我的環境下 virtual mem. 似乎有4G可以用
: 但2G要分給OS,所以剩2G可以用,的確如此~~
: 而physical mem. 即為實際上Ram的記憶體大小
: 我的電腦上有12GB的Ram
: 有這麼多Ram不用真的太浪費了...
: 有沒有人知道在windows 7之下
: 如何能夠調用更多的physical mem.來使用....?
: 謝謝~
: ~
Win7 x64, VS 2008
在 VS 中功能表 Build -> Configuration Manager
這個視窗上方有兩個下拉方塊
你可以先新增一個 solution configuration (或是直接選取既有的)
然後再新增一個 solution platform
如果你在安裝 VS 的時候有安裝完整的 VC compilers
那在接下來跳出的 New Solution Platform 視窗裡面會有 x64 可以選
加好設定完畢之後,別忘了切到新的這組設定來編譯
一個簡單的測試程式:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("pointer size = %d, size_t size = %d\n",
sizeof(void*), sizeof(size_t));
char *p = (char*)malloc(0x123456789LL); // about 4.6GB
if (!p)
puts("failed");
else {
size_t total = _msize(p);
printf("malloc done, p=%p, size=%llX\n", p, total);
memset(p, 0xAA, total);
puts("memset done, press [ENTER] to free memory");
getchar();
free(p);
}
return 0;
}
在我的環境執行其中一次輸出如下:
pointer size = 8, size_t size = 8
malloc done, p=000000013FA30070, size=123456789
memset done, press [ENTER] to free memory
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.244.206
推
08/04 02:37, , 1F
08/04 02:37, 1F