[問題] 讀取TXT中大量資料時 出現已經停止運作
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Code::Blocks
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
我需要讀取一個TXT檔
裡面使用空白或TAB作為分段
在大約讀取超過50K筆(每筆有16的維度)資料時
編譯過後,執行程式時,會出現已經停止運作
此時連MAIN都沒有進去(有用printf測試過)
而50K筆時可正常執行
餵入的資料(Input):
0 11 17 4 10 29 4 18 18 22 14 5 5 1 27 1
1 11 25 2 27 6 21 24 2 3 22 22 21 26 8 5
2 17 6 11 18 9 22 17 19 25 24 23 21 2 3 3
.
.
.
.
預期的正確結果(Expected Output):
可進入MAIN執行後續步驟
錯誤結果(Wrong Output):
XXX.exe已經停止運作
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define num_data 100000//開啟資料筆數
#define num_tran 16 //開啟資料的維度屬性
#define num_server 10 //開啟server數量
#define RegionMax 100
struct data{
int ID;
int Xvelue;
int Yvelue;
int Part;
};
int main(){
FILE *fP_r;
int i,j,k,l;
clock_t start_time,end_time; // 宣告時間點
float TOTLE_time;
start_time = clock();
struct data *base;
base = (struct data *) malloc((num_data+1)*sizeof(struct data));
fP_r = fopen("IndepInput1(200k).txt", "r");
if (!fP_r) {
printf("open file fail...\n");
exit(1);
}
for(i=1;i<=num_data;i++){
base[i].Xvelue = 0;
base[i].Yvelue = 0;
fscanf(fP_r,"%d",&base[i].ID);
for(k=1;k<=num_tran;k++){
if(k<=(num_tran-1)/2){ //將ID後的欄位數的前半當作X值
fscanf(fP_r,"%d",&l);
base[i].Xvelue = base[i].Xvelue + l ;
}
if(k > (num_tran-1)/2 && k < num_tran){ //將欄位後半段設為X值
fscanf(fP_r,"%d",&l);
base[i].Yvelue = base[i].Yvelue + l ;
}
}
//printf("%d %d
%d\n",base[i].ID,base[i].Xvelue,base[i].Yvelue);
}
printf("\n");
printf("*\n");
fclose(fP_r);
到這邊為止是開啟檔案的部分
補充說明(Supplement):
更之前是30K可以開 50K打不開
後來修改一下struct 內部的東西才能夠開到50K
但最終可能需要開到200K
請各位解答一下為什麼會這樣與怎麼樣可以改進><
感激不盡~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 134.208.3.172
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1402991789.A.AAD.html
※ 編輯: sword0921 (134.208.3.172), 06/17/2014 15:58:04
推
06/17 16:01, , 1F
06/17 16:01, 1F
→
06/17 16:05, , 2F
06/17 16:05, 2F
GDB我再試試看
如果是要不到空間的話
有甚麼方法可以解決嗎@@?
※ 編輯: sword0921 (134.208.3.172), 06/17/2014 16:31:38
→
06/17 16:57, , 3F
06/17 16:57, 3F
→
06/17 16:58, , 4F
06/17 16:58, 4F
→
06/17 17:15, , 5F
06/17 17:15, 5F
推
06/17 22:18, , 6F
06/17 22:18, 6F
推
06/17 23:00, , 7F
06/17 23:00, 7F
→
06/18 13:25, , 8F
06/18 13:25, 8F
→
06/18 13:35, , 9F
06/18 13:35, 9F
→
06/18 15:45, , 10F
06/18 15:45, 10F
→
06/18 22:06, , 11F
06/18 22:06, 11F