在海康里面,有个录像功能,其中需要注册回调函数,然后读取内容

我发现每次调用之后,第一次是没有问题的,但是第二次之后就出现:“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”

 

文献提到:

http://topic.csdn.net/u/20080327/14/fb1b0644-2557-4f0d-a39d-16264b22b490.html

NET是自动管理内存,会自动的内存回收
而海康威视的API是C++做的,C++是用户自己管理内存

当在回调函数中执行的时候,.NET中已经把内存回收了,但你还要把这段内存给读出来,就会出现"尝试读取或写入受保护的内存。这通常指示其他内存已损坏"错误

 

Again , google the http://msdn.microsoft.com/en-us/library/aa288468.aspx,再次阅读Tutorial,找到最后一句话:

Also, make sure the lifetime of the delegate instance covers the lifetime of the unmanaged code; otherwise, the delegate will not be available after it is garbage-collected.

 

应该问题是我的回调函数放在class里面了,被内存回收了。。估计是这个问题。看了网上的公开代码,别人的delegate都在class外边。

相关文章:

  • 2021-09-21
  • 2021-05-24
  • 2021-11-03
  • 2021-07-01
  • 2021-11-22
  • 2021-06-06
  • 2021-10-21
猜你喜欢
  • 2021-07-17
  • 2021-12-02
  • 2022-01-05
  • 2021-06-16
  • 2021-12-18
  • 2021-05-27
  • 2021-12-03
相关资源
相似解决方案