[英]Unable to open binary file that exists
我無法打開該特定文件(從此處獲取它,它位於gist.tar.gz內部),但是我可以例如打開查詢文件並正確讀取它。 怎么了? 也許問題在於文件對我來說太大了? 但是我認為,如果是這種情況,我可以將其打開,然后接收bad_alloc
東西。
這是發生了什么:
samaras@samaras-A15:~/parallel/rkd_forest/code$ ./rkd_sam
I/O error : Unable to open the file ../Datasets/gist/gist_base.fvecs
samaras@samaras-A15:~/parallel/rkd_forest/code$ cd ../Datasets/gist/
samaras@samaras-A15:~/parallel/rkd_forest/Datasets/gist$ ls
gist_base.fvecs gist_groundtruth.ivecs gist_learn.fvecs gist_query.fvecs
這是我的代碼(應該可以):
FILE* fid;
fid = fopen(filename, "rb");
if (!fid)
printf("I/O error : Unable to open the file %s\n", filename);
這是文件的權限:
並且其大小為3.8 GB(3,844,000,000字節),我知道此數據集對於這台計算機而言太大 。
結果,我搬到另一台機器上,但是遇到了同樣的問題。
那里的內存(64位,而我的電腦以32位運行):
gsamaras@geomcomp:~/Desktop/code$ free -mt
total used free shared buffers cached
Mem: 3949 3842 106 0 173 3186
-/+ buffers/cache: 483 3466
Swap: 10867 59 10808
Total: 14816 3901 10914
std::cerr << "Error: " << strerror(errno) << std::endl;
給了
Error: Value too large for defined data type
printf("|%s|\\n", filename);
給了
|../Datasets/gist/gist_base.fvecs|
和值取自cmd,並在代碼中我這樣做:
readDivisionSpacefvecs<FT>(test, N, D, argv[8]); // in main()
接着
void readDivisionSpacefvecs(Division_Euclidean_space<T>& ds, int& N, int& D, char* filename) {
FILE* fid;
fid = fopen(filename, "rb");
printf("|%s|\n", filename);
if (!fid) {
printf("I/O error : Unable to open the file %s\n", filename);
std::cerr << "Error: " << strerror(errno) << std::endl;
}
...
}
我也嘗試移動包含數據集的文件夾,但是得到了相同的結果!
您得到的錯誤是EOVERFLOW
,即您閱讀了open
手冊頁的意思
pathname
是指常規文件,太大而無法打開。 通常的情況是,在沒有-D_FILE_OFFSET_BITS=64
的32位平台上編譯的應用程序試圖打開一個大小超過(1 << 31)-1個字節的文件。 另請參見上面的O_LARGEFILE
。 這是POSIX.1-2001指定的錯誤。 在2.6.24之前的內核中,Linux在這種情況下給出了錯誤EFBIG
。
這意味着您使用的是32位平台,並嘗試打開一個無需特殊考慮即可處理的文件。
使用-D_FILE_OFFSET_BITS=64
重新編譯程序,或者直接使用帶有O_LARGEFILE
標志的open
調用。
似乎該程序嘗試在當前目錄( code
)中打開文件,而該文件位於另一個目錄( Datasets/gist'). You did not provide the value of the
Datasets/gist'). You did not provide the value of the
filename變量Datasets/gist'). You did not provide the value of the
,但它應包含文件的完整路徑以進行正確的工作。
你可以試試
cd ../Datasets/gist/
../../code/rkd_sam
如果filename
僅包含基本名稱而不包含任何路徑,則此方法應該起作用。
就fopen()
而言,文件的大小根本不重要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.