有時候會有問題有時候又沒有問題的程式問題 |
尚未結案
|
Saladin
一般會員 ![]() ![]() 發表:18 回覆:9 積分:5 註冊:2005-01-19 發送簡訊給我 |
各位前輩您?好:
小弟我因為現在相當煩躁...,所以標題有點語無倫次,請見諒;
要怎麼樣解決一個有時會產生Access violation,
有時不會的問題,有時候很弔詭的是,明明之前可以跑,現在只是多增個按鈕.連按都沒按它就跑結果竟然爆掉,
我ㄧ直很懷疑...是不是跟動態配置有關?
當掉的地方是,
我按一按鈕做10個浮點數二維陣列的動態配置,
在給值後
因為想留幾個下來就只釋放6個二維陣列,
後來按另外一個鈕有用到剩餘4個的元素,
跑到讀取元素時.....
震驚我的事情發生了...
竟然爆掉...
之前都不會啊?
寫另外一個簡單的測試程式也不會有這種問題....
我的信心變成一片葉子飄落在地面
碎成塵埃而逝.........
程式爆掉的狀況如下
(1)屍體被害前狀況:執行第一個按鈕
|
arisaka_matsuri
高階會員 ![]() ![]() ![]() ![]() 發表:25 回覆:205 積分:231 註冊:2003-10-19 發送簡訊給我 |
|
cashyy
高階會員 ![]() ![]() ![]() ![]() 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
|
Saladin
一般會員 ![]() ![]() 發表:18 回覆:9 積分:5 註冊:2005-01-19 發送簡訊給我 |
按下按鈕
void __fastcall TFormMain::BitBtnTrainClick(TObject *Sender) { runtime=0; //基本資訊獲取 int tdlen=MemoData->GetTextLen();//training data length string td=MemoData->Lines->Text.c_str();//training data //td[tdlen]='\0'; td.insert(td.size(),"\0"); int a=td.size(); int innum=StrToInt(FormControl->EditIn->Text.c_str()); int hidnum=StrToInt(FormControl->EditHid->Text.c_str()); int outnum=StrToInt(FormControl->EditOut->Text.c_str()); char comma=','; twinRowNums test; test=checkTwoNodesNum(td,comma);//test trainingData double rmse;//RootMeanSquareError int digitLen=StrToInt(FormControl->EditLength->Text.c_str()); double la=StrToFloat(FormControl->EditLR->Text.c_str()); double rmset=StrToFloat(FormControl->EditT->Text.c_str());//rootMeanSquareErrorThreshold double rmsed;//rootMeanSquareErrorDifference double rmsedt=StrToFloat(FormControl->EditD->Text.c_str());//rootMeanSquareErrorDifferenceThreshold int et=StrToInt(FormControl->EditE->Text.c_str());;//epochsThreshold int periods=10; double pmp=StrToFloat(FormControl->EditPMP->Text.c_str()); //不分類 int doNothing; ProgressBar1->Max=et; ProgressBar1->Step=1; Chart1->RemoveAllSeries(); ls = new TLineSeries(Chart1); ls->ParentChart = Chart1; gList->Add(ls); Chart2->RemoveAllSeries(); ls2 = new TLineSeries(Chart2); ls2->ParentChart = Chart2; gList->Add(ls2); //用於產生亂數的宣告 randomize();//每次取亂數皆不同 double lb=StrToFloat(FormControl->EditL->Text.c_str());//low bound double hb=StrToFloat(FormControl->EditU->Text.c_str());//high bound int precise=StrToInt(FormControl->EditP->Text.c_str()); double p=0;//前一個 //宣告常用的index變數 int i,j,k; double rTemp;//for rmse double prmse;//previous rmse float stime;//時間差 double hits; double hitRatio; int epochs; //暫存用 double sTemp;//暫存變數,用於累加(sum) char*cTemp=new char[digitLen];//用於轉換成浮點數(convert) //感恩...兩行大人 //char cTemp[10];//用於轉換成浮點數(convert) //digitLen=10; int iIndex,oIndex; char c; int maxAnswerIndex; double maxAnswer; int maxResultIndex; double maxResult; double*rmser=new double[et];//Root Mean Square Error Records runtime ; int number=0;//計算資料筆數 //--------------------------------------------------------------------------- //0.檢查程式是否出錯 if(test.firstNum!=innum)//可能是input nodes跟輸入資料的數目不合,或是下面的狀況 { ShowMessage("警告:網路設定有問題,程式結束!!"); //delete td; exit(1); } if(trainState==2) { if(test.firstNum==0) { ShowMessage("警告:偶數列或奇數列的含有的數目彼此不同,程式結束!!"); //delete td; exit(1); } } else { //配置記憶體空間給weight bias陣列,並做亂數設定(0~1) fpw=new double*[innum]; for(i=0;i再按下按鈕 void __fastcall TFormMain::N_fsaveClick(TObject *Sender) { int innum=StrToInt(FormControl->EditIn->Text.c_str()); int hidnum=StrToInt(FormControl->EditHid->Text.c_str()); int outnum=StrToInt(FormControl->EditOut->Text.c_str()); Memo1->Clear(); FILE*WEIGHT=fopen("weight.txt","wb"); if(trainState==2) { int i,j; for(i=0;i有時候就爆掉 甚至在按了一個鈕時就爆 |
Saladin
一般會員 ![]() ![]() 發表:18 回覆:9 積分:5 註冊:2005-01-19 發送簡訊給我 |
|
enter2004
初階會員 ![]() ![]() 發表:51 回覆:94 積分:34 註冊:2005-04-10 發送簡訊給我 |
|
justdo
高階會員 ![]() ![]() ![]() ![]() 發表:2 回覆:359 積分:222 註冊:2004-08-17 發送簡訊給我 |
|
dllee
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
to Saladin,
您的程式看起來實在是... 太不模組化了,按個按鈕執行了
一大堆的 code 發生問題也不易找出。
建議: 1. 以您的 project 為 neuralP.exe 看來,應該是寫 neural network 的東西,而您的程式看起來就只是用 C 語言在實作,完全沒有用到 C++ 物件的觀念。在 neural network 每個運算單元都是類似的,可以先行開發一個 neural network 運算單元的物件(class),先以單一個 neural network 的運算單元作測試,OK 後再作多個的連結即可完成整體的運算。 2. 可以善用 LOG 的方式來除錯,例如:
【Delphi】【推薦】一套專門處理程式 Log 的 Library : Log4d
http://delphi.ktop.com.tw/topic.php?topic_id=77344
或包大人推薦的 DebugView
http://delphi.ktop.com.tw/quicksearch.exe/quicksearch?SearchStr=DebugView
可以由 LOG 找出到底程式執行到那一個部分就掛了。 3. 善用 try...catch 的方式自己攔截 exception
在可能會有問題的程式碼,加上
try { // 可能會 Exception 的程式碼 } catch(...) { // 真的 Exception 要如何處置 }to enter2004, 您也可以試試以上2,3點,來找問題。 C# 初學者請多指教
------
http://www.ViewMove.com |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |