gcroot没有价值
我对非托管代码中的托管对象有一个奇怪的问题。我有这个 C++/CLI 模块,可以桥接 C++ 和 C# 代码。我有一个这样的结构:
template <class T>
struct ManagedReference
{
gcroot<T^> addonHost;
}
现在,在某个时刻我创建此托管引用的实例并设置 addonHost。一切都很好,我可以使用手柄了。
但是,在某些情况下(恐怕需要大量上下文描述)无法评估该值:
在这种情况下,使用 addonHost 调用方法会导致“找到的入口点”异常。
正如您从屏幕截图中看到的,这不是两个不同的实例,两个不同的句柄。是一模一样的。我不明白为什么在某些情况下不评估“价值”。也许我怎样才能抓住它。因为它不为空。
我还应该提到的是,我有几个 gcroot
,除了一个 gcroot
之外,所有这些都存在此问题。
更新
这是调试器在执行期间显示的内容。该对象已创建并可用,然后在某个时刻,该值“消失”,并且在下一次调用时它仍然存在。但这是非常可重复的。这不是随机的。
handle 0x0E1618EC void*
value 0x106396d8 { m_host=0x10638e04 } <-- object is available here
handle 0x0E1618EC void*
value 0x1020e558 { m_host=0x1020e4f0 } <-- object moved in memory
handle 0x0E1618EC void*
value <-- no value here
handle 0x0E1618EC void*
value 0x1020e558 { m_host=0x1020e4f0 } <-- object 'is back'
I have a curious problem with a managed object in unmanaged code. I have this C++/CLI module that bridges C++ and C# code. I have a structure like this:
template <class T>
struct ManagedReference
{
gcroot<T^> addonHost;
}
Now, at some point I create an instance of this managed reference and set the addonHost. All is well, I am able to use the handle.
However, in some cases (would require to much contextual description I'm afraid) the value cannot be evaluated:
In this case, calling a method with addonHost results in a "Entry point for found" exception.
As you can see from the screenshots, it is not two difference instances, two different handles. It's the very same. I don't understand how come in some situation the "value" is not evaluated. And maybe how I could catch that. Because it's not null.
What I should also mention is that I have several gcroot<T>
and all of them have this problem, except one that is a gcroot<System::String>
.
UPDATE
Here is what debugger shows during execution. The object is created and available, then at some point, the value is 'vanishing', and at the next call it's still there. But this is very reproducible. It's not random.
handle 0x0E1618EC void*
value 0x106396d8 { m_host=0x10638e04 } <-- object is available here
handle 0x0E1618EC void*
value 0x1020e558 { m_host=0x1020e4f0 } <-- object moved in memory
handle 0x0E1618EC void*
value <-- no value here
handle 0x0E1618EC void*
value 0x1020e558 { m_host=0x1020e4f0 } <-- object 'is back'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许它有助于初始化
gcroot
。尝试:Maybe it would help to initialize the
gcroot
. Try: