简体   繁体   English

如何在C#中区分托管代码和非托管代码

[英]How can I distinguish between managed & unmanaged code in C#

As per MSDN, 根据MSDN,

Managed Code - Code that could be understood and managed by CLR

Unmanaged Code - Code that could not handled by CLR 

But I am wondering how do I identify which resource or class is CLR compliant & which Not. 但是我想知道如何确定哪个资源或类符合CLR,哪些不符合。

I referred below links 我在下面提到了链接

If I am using EF (LINQ to Entities), it is translated to native SQL. 如果我使用的是EF(LINQ to Entities),它将转换为本机SQL。 SO all LINQ falls under Unmanaged Code category? 因此,所有LINQ都属于“非托管代码”类别吗?

Thanks! 谢谢!

"unmanaged" here is referring to in-process execution of non-CLR code (don't confuse that with "CLR compliant", whatever that might mean); 这里的“非托管”是指非CLR代码的进程内执行(无论将其与“符合CLR的规范”混为一谈,无论其含义是什么); so - EF and LINQ are managed (or mostly managed), but they often talk indirectly to unmanaged dlls (think: C/C++ dlls, etc - nothing to do with the CLR) at some point - for example, many of the ADO.NET providers are really P/Invoke layers to an unmanaged database drivers - or unsafe code that talks to manually allocated raw memory in the local process (a chunk of memory allocated via Marshal.AllocHGlobal , for example). 因此-EF和LINQ是受管理的(或大部分受管理的),但它们有时在某些时候与非受管理的 dll(例如C / C ++ dll等,与CLR无关)进行间接对话-例如,许多ADO。 NET提供程序实际上是非托管数据库驱动程序的P / Invoke层-或与本地进程中手动分配的原始内存(例如,通过Marshal.AllocHGlobal分配的内存块)进行对话的unsafe代码。 Usually these exist in a dual state: there's a managed layer that abstracts and hides the unmanaged layer - so application level code rarely talks to unmanaged code directly. 通常,它们以双重状态存在:有一个托管层可以抽象并隐藏非托管层-因此应用程序级代码很少直接与非托管代码对话。

The fact that native SQL is involved is unrelated, as that isn't "managed" or "unmanaged" - it isn't in-process, so it is a different category altogether. 涉及本机SQL的事实是无关的,因为它不是“托管” “非托管”的-它不是进程内的,因此完全是另一类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在C#中区分托管资源和非托管资源? TextFieldParser是否不受管理? - How do we distinguish between managed and unmanaged resources in C#? Is TextFieldParser unmanaged? c#托管代码和非托管代码之间的共享内存 - c# shared memory between managed and unmanaged code 从C#调用非托管C ++库(dll):如何在托管代码和非托管代码之间正确传递数据 - Calling unmanaged C++ library (dll) from C# : How to properly pass data between managed and unmanaged code 如何在托管 (C#) 和非托管 (C++) 代码之间来回传递数组内容 - How to pass array contents back and forth between managed (C#) and unmanaged (C++) code 从非托管C ++代码调用托管C#组件,我该如何定义配置 - calling managed c# component from unmanaged c++ code, how do i define config 我可以在非托管Delphi EXE中使用托管C#DLL吗? - Can I use managed C# DLL in unmanaged Delphi EXE? 如何将结构从C#托管结构传递到C ++非托管DLL并得到结果结构? - How can I pass struct from C# managed to C++ unmanaged DLL and get struct in result? 从托管C#回调非托管代码 - Callback unmanaged code from managed C# C#托管代码和C ++非托管代码之间的字符串混合编程 - mixed programming for a string between C# managed code and c++ unmanaged code 如何在C#中处理托管和非托管对象? - How to dispose managed and unmanaged objects in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM