如何在 gcc 中宣告很大的陣列?
我開的陣列有這麼大,大概 6G
double arr[1000000][686];
這個陣列在 Visual C++ 6.0 中 compile 會過
只是會警告說記憶體可能會不夠
可是在 gcc 中
就會因為陣列太大 compile 不過
錯誤訊息大概長這樣
(.text+0xff): relocation truncated to fit: R_X86_64_32S against symbol ...
我有試過把陣列調小,compile就過了
可是我記憶體有16G
不開那麼大就浪費了
請各位懂 GCC 的專家解答
感謝^^
回 丹尼爾:
這個程式是寫給自己用的,而且只是要做一些數學運算,所以不用擔心這些問題。
回 bean_bottom_2:
確定是在64-bit的機器上,而且也是用64-bit來編譯。
用 g++ -m64 這個指令應該沒錯吧。
回 bean_bottom_2:
加上 -mcmodel=medium 後成功了
感謝^^
2 個解答
- bean_bottom_2Lv 51 0 年前最佳解答
Are you sure you are using gcc on a 64 bit machine and also, did you invoke the 64 bit compilation option??
Your array is larger than the area it is being created. It is very likely you have a 32 bit OS or without a 64 bit option turned on during compilation.
2009-05-01 06:14:16 補充:
Since you have tried -m64, have you try -mcmodel=medium??
- 丹尼爾Lv 41 0 年前
我只是好奇為何需要那麼大連續記憶體的空間?
還有姑且不論其他任何技術上的問題..當你要配置一塊連續大型的記憶體空間基本上要用動態記憶體配置,由作業系統幫你檢查是否配置成功...不然...後果是很慘的