封送处理-这是什么,为什么我们需要它? [英] Marshaling – what is it and why do we need it?

查看:85
本文介绍了封送处理-这是什么,为什么我们需要它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是编组,为什么我们需要它?

What is marshalling and why do we need it?

我很难相信我不能通过C#到C的线路发送int,而不得不将其编组.为什么C#不能只用开始和结束信号发送32位,告诉C代码它已经接收到int?

I find it hard to believe that I cannot send an int over the wire from C# to C and have to marshall it. Why can't C# just send the 32 bits over with a starting and terminating signal, telling C code that it has received an int?

如果有任何很好的教程或网站介绍为什么我们需要编组以及如何使用它,那就太好了.

推荐答案

因为不同的语言和环境具有不同的调用约定,不同的布局约定,不同的原语大小(请参见C#中的char和C中的char) ,不同的对象创建/销毁约定以及不同的设计准则.您需要一种方法来将这些东西从管理土地中带入某个地方,在该地方非管理土地可以看到和理解它,反之亦然.这就是编组的目的.

Because different languages and environments have different calling conventions, different layout conventions, different sizes of primitives (cf. char in C# and char in C), different object creation/destruction conventions, and different design guidelines. You need a way to get the stuff out of managed land an into somewhere where unmanaged land can see and understand it and vice versa. That's what marshalling is for.

这篇关于封送处理-这是什么,为什么我们需要它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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