With C++, I get pointer with 0xcdcdcdcd when creating a class - what is happening? [duplicate]

守給你的承諾、 提交于 2019-12-06 11:58:49

问题


----------------EDIT-----------------------

I was grabbing the wrong value for comparison, the cdcdcdcd was coming from somewhere else. I still have my methods throwing exceptions before they are even reached, but my problem lies elsewhere, I wish there was a way to just "unpost" my original question. Thanks for the help.

----------------EDIT-----------------------

I have a class (MyClass) I have inherited from some third party class (which in turn derives from direct show classes - from CBaseFilter if this matters). I write this code:

MyClass* val = NULL;
val = new MyClass(); // Create an instance of the class.

Attempting to make method calls results in a thrown exception. With a little sleuthing I found that when I dereference val (val itself seems valid... something like 0x0777fc90), it contains 0xcdcdcdcd. I looked around and it seems that this might indicate that the memory has been allocated on the heap, but not initialized.

What does that mean?! How can the call to new succeed (val != NULL) and yet the memory isn't initialized enough to have a pointer to it? Is it possible that something went wrong with some of the base class initialization? And if so - what am I looking for?


回答1:


0xCDCDCDCD is a debugging value that comes from the bowels of the C runtime library. When you allocate a block of memory in a debug build, it's initialized to this spurious value in the hope of catching bugs. 0xCDCDCDCD is non-NULL and is never a valid memory pointer.

Is there an HRESULT that passes up through from DirectShow that you can check?

Try calling WINAPI function GetLastError() and see what that shows.



来源:https://stackoverflow.com/questions/8275418/with-c-i-get-pointer-with-0xcdcdcdcd-when-creating-a-class-what-is-happenin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!