应用域有什么用? [英] What are app domains used for?

查看:22
本文介绍了应用域有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大致了解 AppDomain 是什么,但我并不完全了解 AppDomain 的用途.

I understand roughly what an AppDomain is, however I don't fully understand the uses for an AppDomain.

我参与了一个基于 C#/C++ 的大型服务器应用程序,我想知道如何使用 AppDomains 来提高稳定性/安全性/性能.

I'm involved in a large server based C# / C++ application and I'm wondering how using AppDomains could improve stability / security / performance.

特别是:

  • 我了解一个域中的错误或致命异常不会影响在同一进程中运行的其他应用程序域 - 这是否也适用于非托管/C++ 异常,甚至可能是堆损坏或其他内存问题.
  • AppDomain 间通信如何工作?
  • 使用 AppDomains 与简单地生成多个进程有何不同?

推荐答案

AppDomain 的基本用例是在托管 3rd 方代码的环境中,因此不仅需要动态加载程序集而且也卸载它们.

The basic use case for an AppDomain is in an environment that is hosting 3rd party code, so it will be necessary not just to load assemblies dynamically but also unload them.

无法单独卸载程序集.因此,您必须创建一个单独的 AppDomain 来容纳可能需要卸载的任何内容.然后,您可以在必要时删除并重建整个 AppDomain.

There is no way to unload an assembly individually. So you have to create a separate AppDomain to house anything that might need to be unloaded. You can then trash and rebuild the whole AppDomain when necessary.

顺便说一下,CLR 的任何功能都无法保护破坏堆的本机代码.最终,CLR 是本地实现的,并共享相同的地址空间.因此,进程中的本机代码可以在 CLR 内部乱涂乱画!隔离不良行为(即大多数)本机代码的唯一方法是在操作系统级别进行实际进程隔离.启动多个 .exe 进程并让它们通过某种 IPC 机制进行通信.

By the way, native code corrupting the heap cannot be protected against by any feature of the CLR. Ultimately the CLR is implemented natively and shares the same address space. So native code in the process can scribble all over the internals of the CLR! The only way to isolate badly behaved (i.e. most) native code is actual process isolation at the OS level. Launch mutiple .exe processes and have them communicate via some IPC mechanism.

这篇关于应用域有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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