[問題] malloc在VS2015會讓程式卡住

作者: asdfg1597860 (Jay)   2018-12-12 10:01:59
開發平台(Platform): (Ex: Win10, Linux, ...)
WIN10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Visual Studio 2015
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MFC
問題(Question):
想把一個在VS2003上的專案搬到VS2015並升級64位元
不過程式跑到下面的code時會卡住
CRule** m_pList;
m_pList = (CRule**) malloc (nums*sizeof(CRule*));
CRule* pData = new CRule();
m_pList[i] = pData;
但我改寫成new 時程式就不會卡住了
m_pList = new CRule*[nums * suzeof(CRule)];
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
補充說明(Supplement):
不過同樣的指令在VS2003 是正常的
目前我唯一能懷疑的是在sizeof(CRule*) 時 64bit 會抓8byte 但32bit 會抓4byte
不過我想這因該不會影響程式運作
再請前輩賜教 謝謝
作者: jerryh001   2018-12-12 10:27:00
講個無關的 那個new應該是[num]才對?
作者: tomsawyer (安安)   2018-12-12 12:27:00
那個是malloc用法吧
作者: loveme00835 (髮箍)   2018-12-12 16:54:00
完全看不出你到底想配置幾個 element那你知道 new [] 中括號裡面該擺什麼嗎?
作者: xam (聽說)   2018-12-12 22:27:00
這種問題你只能自己查,通常是自己程式的問題

Links booklink

Contact Us: admin [ a t ] ucptt.com