P/Invoke是否执行DLL,然后将其关闭? [英] Does P/Invoke execute the DLL and then shut it down?

查看:83
本文介绍了P/Invoke是否执行DLL,然后将其关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用C#P/调用某个DLL,那么实际的C ++ DLL是否会在调用过程中运行,然后关闭,从而破坏所有已使用的内存?还是我每次调用静态函数时,.NET都会在非托管堆"中负责C ++ DLL所使用的内存,并将指向这些对象的指针提供给C ++ DLL?

If I use C# to P/Invoke a certain DLL, will the actual C++ DLL be run for the duration of the call and then be shut down, destroying all used memory? Or will .NET take charge of the memory used by the C++ DLL in an unmanaged "heap" and give pointers to those objects to the C++ DLL everytime I call a static function?

当我需要某个C ++项目具有其内存持久性时,是否应该创建ActiveX/COM Server使其具有内存持久性,并且仍能够从C#调用它?

When I need a certain C++ project to have its memory persistant, should I be creating an ActiveX/COM Server to have its memory persist, and yet be able to call it from C#?

推荐答案

如果我使用C#P/调用某个DLL,那么实际的C ++ DLL是否会在调用过程中运行,然后关闭,从而破坏所有已使用的内存?

If I use C# to P/Invoke a certain DLL, will the actual C++ DLL be run for the duration of the call and then be shut down, destroying all used memory?

不.一旦DLL被加载,它将保持加载状态. DLL的生存期与函数调用有关.这意味着DLL中具有静态存储的变量将保留到最初的p/invoke调用之后.

No. Once the DLL is loaded it will stay loaded. The DLL's lifetime is not tied to a function call. This means that variables in the DLL that have static storage persist beyond the initial p/invoke call.

这篇关于P/Invoke是否执行DLL,然后将其关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆