[问题] 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