使用 C++,我在创建类时得到带有 0xcdcdcdcd 的指针 - 发生了什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8275418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
With C++, I get pointer with 0xcdcdcdcd when creating a class - what is happening?
提问by Steven
----------------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.
我获取了错误的比较值,cdcdcdcd 来自其他地方。我仍然有我的方法在它们被到达之前抛出异常,但我的问题在于其他地方,我希望有一种方法可以“取消”我的原始问题。谢谢您的帮助。
----------------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),我是从某个第三方类继承的(这些类又派生自直接显示类 - 如果这很重要,则来自 CBaseFilter)。我写这个代码:
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.
尝试进行方法调用会导致抛出异常。通过一些调查,我发现当我取消引用 val(val 本身似乎有效......类似于 0x0777fc90)时,它包含 0xcdcdcdcd。我环顾四周,似乎这可能表明内存已在堆上分配,但尚未初始化。
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?
这意味着什么?!对 new 的调用怎么会成功(val != NULL),但内存还没有初始化到足以有指向它的指针?某些基类初始化是否可能出现问题?如果是这样 - 我在寻找什么?
回答by bobobobo
0xCDCDCDCD 是来自 C 运行时库内部的调试值。当您在调试版本中分配内存块时,它会被初始化为这个虚假值,以期捕获错误。0xCDCDCDCD 是非 NULL 并且永远不是有效的内存指针。
Is there an HRESULT that passes up through from DirectShow that you can check?
是否有从 DirectShow 传递过来的 HRESULT 可以检查?
Try calling WINAPI function GetLastError()and see what that shows.
尝试调用 WINAPI 函数GetLastError()并查看显示的内容。