如何在C ++和C#之间共享一个大字节数组 [英] How to share a big byte array between C++ and C#

查看:155
本文介绍了如何在C ++和C#之间共享一个大字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在驻留在DLL中的C ++程序和C#程序之间共享一个巨大的(多兆字节)字节数组。

I need to share a huge (many megabytes) byte array between a C++ program residing in a DLL and a C# program.

我需要实时性能,所以它是非常重要的,我可以在两者之间以有效的方式分享它,所以在C ++中使用C ++操作数据后每次都会为C#创建一个新的副本,但是我发现的这些示例似乎依赖于这个。

I need realtime performance, so it is very important I can share it between the two in an efficient way, so making a new copy for it in C# every time after the data is manipulated in C++ is not an option, yet the examples I have found so far seems to depend on this.

有可能以有效的方式共享数组吗?如果是这样,怎么样?

Is it possible to share the array in an efficient way? And if so, how?

推荐答案

在当前版本的.NET中,任何多兆字节数组都将结束于大对象堆,永不动。但是,为了安全起见,您应该将该阵列固定为fejesjoco说。然后,C ++代码可以将指针保存到.NET数组中,并将其更新到原位。

In current versions of .NET, any multi-megabyte array will end up on the large object heap and never move. However, to be safe, you should pin the array as fejesjoco said. Then the C++ code can save a pointer into the .NET array and update it in-place.

这篇关于如何在C ++和C#之间共享一个大字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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