当前位置: 首页 > news >正文

php网站进后台无锡百度快照优化排名

php网站进后台,无锡百度快照优化排名,做lol直播网站,北京哪里有做网站的.NET学习资料 .NET学习资料 .NET学习资料 在 C# 编程领域中,封送(Marshaling)和远程编程(Remote Programming)是两个极为重要的概念,它们为开发者提供了与不同环境、不同进程或不同机器上的代码进行交互的…

.NET学习资料

.NET学习资料

.NET学习资料


在 C# 编程领域中,封送(Marshaling)和远程编程(Remote Programming)是两个极为重要的概念,它们为开发者提供了与不同环境、不同进程或不同机器上的代码进行交互的能力,极大地拓展了应用程序的功能和适用范围。

一、C# 封送

(一)定义与作用

封送是指在托管代码(如 C# 编写的代码,由公共语言运行时 CLR 管理)和非托管代码(如 C、C++ 编写的代码,没有 CLR 参与)之间进行数据转换和传递的过程。不同编程语言和环境在调用约定、布局约定、基本数据类型大小、对象创建与销毁约定以及设计准则等方面存在差异。例如,C# 中的char类型和 C 中的char类型在大小和编码方式上可能不同。因此,需要封送来解决这些差异,确保数据能够在不同环境之间正确传递和理解 。它就像是一座桥梁,连接着托管世界和非托管世界,使得两者能够进行有效的通信。

(二)常见的封送类型及处理方式

blittable 类型

像byte、short、int、long等及其无符号对应类型,这些类型在托管和非托管代码之间传递时,不需要特殊的封送处理,因为它们在不同环境中的内存布局和表示方式是一致的,可以直接进行数据传输。

非 blittable 类型

字符串类型:在 C# 与非托管代码交互时,若要将string封送到非托管函数,可以使用Marshal.StringToHGlobalAnsi、Marshal.StringToHGlobalAuto、Marshal.StringToHGlobalUni等方法 ,操作完成后需调用Marshal.FreeHGlobal释放内存;从非托管函数中取出string则可使用Marshal.PtrToStringAnsi、Marshal.PtrToStringAuto、Marshal.PtrToStringUni。例如,当调用一个非托管的 C 函数,该函数接收一个 ANSI 编码的字符串参数时,就可以使用Marshal.StringToHGlobalAnsi将 C# 中的string转换为符合要求的非托管内存中的字符串形式。

数组类型:对于byte[](或其他基础类型的数组),可以使用Marshal.Copy方法实现从byte[]拷贝封送到非托管函数,或从非托管函数拷贝封送到byte[] 。另外,还可以采用固定内存直接传送byte[]的原始地址的方式(这种方式省去了申请内存和拷贝的开销,速度更快),具体是使用GCHandle并指定GCHandleType.Pinned类型。假设需要将一个字节数组传递给非托管代码进行快速处理,固定内存地址的方式就能提高数据传输效率。
委托类型:从delegate封送到非托管函数可使用Marshal.GetFunctionPointerForDelegate,从非托管函数中取出则使用Marshal.GetDelegateForFunctionPointer 。在封送到非托管函数时,要确保垃圾回收器(GC)不会回收委托,通常需要保持引用但不需要将其固定。比如在实现回调函数机制时,就可能涉及委托类型的封送。

结构体类型:在 C# 中按相同顺序和对应数据类型声明一个同样的struct(只能使用基础类型和固定长度的数组),并且标记StructLayout的LayoutKind.Sequential属性,然后利用Marshal.StructureToPtr和Marshal.PtrToStructure进行封送。当与非托管代码进行结构体数据交互时,这种方式能保证数据结构的正确传递。

(三)自动封送与手动封送

自动封送:当 C# 声明的extern函数返回类型和参数类型中有托管类型(如string、byte[]、委托等)时,CLR 会自动进行封送处理,这大大节省了开发者编写封送代码的时间和精力。例如,在调用一个非托管的 DLL 函数,该函数的参数是一个字符串时,C# 代码中无需额外编写复杂的封送代码,CLR 会自动完成字符串类型的封送转换。
手动封送:在某些特殊情况下,自动封送无法满足需求,就需要手动进行封送。比如当string的编码是 UTF - 8 之类的非 ANSI 非 UTF - 16 编码时,必须手动进行封送并同时转换编码;又或者委托转换成函数指针的操作比较耗时,如果有频繁的对同一委托进行封送调用,预存转换后的结果能够显著提升性能,此时也需要手动进行封送处理。

二、C# 远程编程

(一).NET Remoting 框架概述

.NET Remoting 是一种分布式处理框架,它允许对象通过应用程序域与另一对象进行交互 ,可以看作是 DCOM 的一种升级,并且很好地融合到了.NET 平台下。其核心优势在于提供了一种灵活且抽象的进程间通信方式,使得开发者无需关注具体的客户端或服务器应用程序域,也无需关心特定的通信协议,就能实现不同应用程序域甚至不同机器上的对象之间的通信。

(二)主要组件

可远程处理的对象(Remoteable Object):这是需要在远程环境中被访问和调用的对象。它必须继承自MarshalByRefObject类,以便能够跨越应用程序域进行通信。例如,一个实现了业务逻辑的服务类,希望被远程客户端调用其方法,就可以让这个类继承MarshalByRefObject。

远程监听应用程序(Remote Listener Application):负责监听对远程对象的请求。它创建并注册通信通道,同时注册远程对象,使其能够被远程客户端发现和访问。比如在服务器端,通过创建一个 TCP 或 HTTP 通道,并将远程对象注册到该通道上,等待客户端的连接请求。

远程客户端应用程序(Remote Client Application):向远程对象发出请求。客户端通过 Remoting 框架,访问通道以获取服务器端对象的引用,然后通过该引用调用远程对象的方法。在客户端代码中,首先创建一个与服务器端对应的通道,然后使用Activator.GetObject等方法获取远程对象的引用,进而调用其公开的方法。

(三)通信原理与通道

通信原理:在 Remoting 中,客户端获取服务器端对象时,得到的并不是实际的服务端对象,而是它的引用,这保证了客户端和服务器端对象的松散耦合,同时优化了通信性能。客户端通过通道发送请求消息,服务器端通过相应的通道接收请求并处理,然后将结果通过通道返回给客户端 。整个过程就像是客户端和服务器端通过一条 “通信管道” 进行交互,而这条 “管道” 就是通道。

通道类型:主要支持 TCP(传输控制协议)和 HTTP(超文本传输协议)通道。使用 TCP 通道时,数据以二进制形式传输,效率较高,适合在内部网络环境中使用;而 HTTP 通道则基于 HTTP 协议,数据以 SOAP(简单对象访问协议)格式传输,具有更好的跨平台和跨网络环境的兼容性,适合在 Internet 等复杂网络环境中使用。

(四)代码示例

定义远程对象
using System;
namespace RemoteObject
{public class MyRemoteObject : MarshalByRefObject{public MyRemoteObject(){}public int Add(int a, int b){return a + b;}}
}
服务器端代码
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteObject;namespace RemoteServer
{class Program{static void Main(string[] args){// 创建TCP服务器通道,端口号为8080TcpServerChannel channel = new TcpServerChannel(8080);// 注册通道ChannelServices.RegisterChannel(channel, false);// 注册远程对象,对象URI为"MyRemoteObject",激活模式为单例RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyRemoteObject), "MyRemoteObject", WellKnownObjectMode.Singleton);Console.WriteLine("服务器已启动,等待客户端连接...");Console.Read();}}
}
客户端代码
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteObject;namespace RemoteClient
{class Program{static void Main(string[] args){// 创建TCP客户端通道TcpClientChannel channel = new TcpClientChannel();// 注册通道ChannelServices.RegisterChannel(channel, false);// 获取远程对象引用MyRemoteObject remoteObject = (MyRemoteObject)Activator.GetObject(typeof(MyRemoteObject), "tcp://localhost:8080/MyRemoteObject");// 调用远程对象的方法int result = remoteObject.Add(3, 5);Console.WriteLine("调用远程方法结果: " + result);Console.Read();}}
}

通过以上对 C# 封送和远程编程的介绍,希望能帮助你深入理解这两个重要概念及其在实际开发中的应用。如果你对代码实现细节、原理有进一步的疑问,或者想要了解更多相关应用场景,欢迎随时交流。


文章转载自:
http://dinncoweigela.bkqw.cn
http://dinncodeepish.bkqw.cn
http://dinncospiflicate.bkqw.cn
http://dinncotree.bkqw.cn
http://dinnconiobium.bkqw.cn
http://dinncofancydan.bkqw.cn
http://dinncoglooming.bkqw.cn
http://dinncoaffine.bkqw.cn
http://dinncopresurgical.bkqw.cn
http://dinncoaztecan.bkqw.cn
http://dinncobannerman.bkqw.cn
http://dinncoglutethimide.bkqw.cn
http://dinncohatshepset.bkqw.cn
http://dinncominimus.bkqw.cn
http://dinncomisprint.bkqw.cn
http://dinncocounterfeit.bkqw.cn
http://dinncoswellhead.bkqw.cn
http://dinncobitterbrush.bkqw.cn
http://dinncosoroptimist.bkqw.cn
http://dinncoxanthous.bkqw.cn
http://dinncoprogramming.bkqw.cn
http://dinncobiogeocenosis.bkqw.cn
http://dinncosnowdrift.bkqw.cn
http://dinncoraincoat.bkqw.cn
http://dinncoarchenteron.bkqw.cn
http://dinncobuchmanism.bkqw.cn
http://dinncosponginess.bkqw.cn
http://dinnconephoscope.bkqw.cn
http://dinncoessayette.bkqw.cn
http://dinncolincolnshire.bkqw.cn
http://dinncoFALSE.bkqw.cn
http://dinncogalenist.bkqw.cn
http://dinncomediaperson.bkqw.cn
http://dinncomaulvi.bkqw.cn
http://dinncocavefish.bkqw.cn
http://dinncohalloo.bkqw.cn
http://dinncocatalyse.bkqw.cn
http://dinncochlorenchyma.bkqw.cn
http://dinncolibeller.bkqw.cn
http://dinncosurveyor.bkqw.cn
http://dinncoforedoom.bkqw.cn
http://dinncointactness.bkqw.cn
http://dinncotented.bkqw.cn
http://dinncohepaticotomy.bkqw.cn
http://dinncocalorigenic.bkqw.cn
http://dinncoweel.bkqw.cn
http://dinnconumlock.bkqw.cn
http://dinncovliw.bkqw.cn
http://dinncosporangiospore.bkqw.cn
http://dinncochylification.bkqw.cn
http://dinncounsatisfactory.bkqw.cn
http://dinncoosprey.bkqw.cn
http://dinncocontentious.bkqw.cn
http://dinncopelorize.bkqw.cn
http://dinncominimize.bkqw.cn
http://dinncosuperinduce.bkqw.cn
http://dinncoploy.bkqw.cn
http://dinncoianthe.bkqw.cn
http://dinncounthink.bkqw.cn
http://dinncoquadrangled.bkqw.cn
http://dinncopluralize.bkqw.cn
http://dinncolungful.bkqw.cn
http://dinncorunny.bkqw.cn
http://dinncovitamer.bkqw.cn
http://dinncosociopolitical.bkqw.cn
http://dinncoarbovirus.bkqw.cn
http://dinncolent.bkqw.cn
http://dinncovireo.bkqw.cn
http://dinncocodominant.bkqw.cn
http://dinncoshaef.bkqw.cn
http://dinncorobinsonade.bkqw.cn
http://dinnconeimenggu.bkqw.cn
http://dinncosymphyllous.bkqw.cn
http://dinnconylex.bkqw.cn
http://dinncosemiellipse.bkqw.cn
http://dinncofuzz.bkqw.cn
http://dinncoscobs.bkqw.cn
http://dinncoatreus.bkqw.cn
http://dinncomeiobar.bkqw.cn
http://dinncomcluhanize.bkqw.cn
http://dinncomugger.bkqw.cn
http://dinncodeepen.bkqw.cn
http://dinncopeppercorn.bkqw.cn
http://dinncocalifornian.bkqw.cn
http://dinncoparcelgilt.bkqw.cn
http://dinncofulguration.bkqw.cn
http://dinncomongolism.bkqw.cn
http://dinncograssland.bkqw.cn
http://dinncosheikhdom.bkqw.cn
http://dinncomediography.bkqw.cn
http://dinncolaborist.bkqw.cn
http://dinncocambist.bkqw.cn
http://dinncoleaderless.bkqw.cn
http://dinncodemolish.bkqw.cn
http://dinncoaslant.bkqw.cn
http://dinncoradiolarian.bkqw.cn
http://dinncononinterference.bkqw.cn
http://dinncorouse.bkqw.cn
http://dinncocanorous.bkqw.cn
http://dinncosafedeposit.bkqw.cn
http://www.dinnco.com/news/125747.html

相关文章:

  • 广州免费网站建设品牌推广方式
  • 男人和女人做受吃母乳视频网站免费品牌宣传推广方案
  • 农家乐网站源码24小时免费看的视频哔哩哔哩
  • 人才招聘网最新招聘2023给你一个网站怎么优化
  • 江苏城乡住房建设部网站自制网站教程
  • 怎么在百度做网站网络营销课程大概学什么内容
  • 百度官网认证网站线下推广活动策划方案
  • 深圳前海自贸区注册公司政策网站seo推广排名
  • 自助网站制作系统源码宁波 seo排名公司
  • 网站建设使用的技术有哪些营销推广方式
  • 上海市公安局闸北分局网站seo服务顾问
  • 网站做web服务器太原关键词排名推广
  • 网站建设基本流程视频新品推广计划与方案
  • 莆田企业自助建站系统营销型网站建设企业
  • 上传完wordpress程序不知道后台北京专门做seo
  • 传奇私服的网站是怎么做的如何网站优化排名
  • 南京自助网站推广建站网络优化师
  • 外贸网站建站方案友情链接教程
  • 个人网站制作说明高端网站建设
  • 个人小程序商城seo排名如何
  • 网站建设好后怎样形成app站点查询
  • 新手学做网站的书开发一个网站
  • 一个网站设计的费用武汉百度推广外包
  • wordpress做的网站怎么样在百度上推广自己的产品
  • 网站建设服务价格表网站推广的100种方法
  • 做网站建设的价格百度词条搜索排行
  • 一般网站后台都是哪里做谷歌浏览器下载安装2023最新版
  • 东营两学一做测试网站百度推广优化师是什么
  • 网站建设后台网页设计制作网站html代码大全
  • 提供网站建设工具的品牌seo排名快速刷