如何绕过Marshal.Copy(32bit)长度限制? [英] How to get around Marshal.Copy (32bit) length limit?

查看:82
本文介绍了如何绕过Marshal.Copy(32bit)长度限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在托管(C#)和非托管(C ++ Win32)代码之间来回移动数据。我可以使用 Marshal.Copy ,直到 Marshal.Copy 具有一个签名的32位int(2GB)长度限制。

I'm trying to move data back/forth between managed (C#) and unmanaged (C++ Win32) code. I can use Marshal.Copy and it works just fine until the datasets get bigger > 2GB as Marshal.Copy has a signed 32 bit int (2GB) limit for length.

任何想法如何解决这个问题?目前,我在托管方使用 AllocHGlobal(IntPtr),在非托管方使用 .ToPointer()。如果我不能使用 Marshal.Copy 来回移动大数据(> 2GB),该怎么用?

Any idea how to get around this? Currently I use AllocHGlobal(IntPtr) on the managed side and .ToPointer() on the unmanaged side. If I can't use Marshal.Copy to move large data (> 2GB) back/forth what can I use?

推荐答案

我的第一个反应是:为什么要复制2GB以上的数据?

My first reaction was: why are your copying 2GB+ of data?

也许您的应用程序约束不允许这样做,但是在我看来,如果您的数据集大于框架所允许的数据集,那么您不应该查找绕过框架的技巧。完全可以使用另一种访问方法呢?

Perhaps your application constraints won't allow it, but it seems to me that if your data set is that larger than what is allowed by the framework you should not be looking for trick to get around the framework. How about another method of access altogether?

有很多方法可以解决此问题。对于初学者,您可以将内存包装在流中,然后将数据拉入非托管代码中。您还可以创建自己的界面,以将数据整合在一起。内存映射文件也会浮现在脑海。

There are numerous ways around this problem. For starters you could wrap the memory in a stream and pull the data into the unmanaged code. You could also create your own interface to bring the data in piece meal. Memory mapped files come to mind as well.

在不知道应用程序具体约束的情况下,也许您无法更改非托管代码,我建议您找到其他方法而不是工作围绕框架。

Without knowing the specific contstraints of the application, maybe you cannot change the unmanaged code, I would suggest finding another method rather than working around the framework.

这篇关于如何绕过Marshal.Copy(32bit)长度限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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