简体   繁体   English

如何在C#中分配较大的连续内存块(Win + Linux)

[英]How can I allocate a large contiguous memory chunk in C# (win + linux)

I'm searching for a memory allocation method in C# that provides a contiguous chunk of memory (> 4 GiB). 我正在寻找C#中的内存分配方法,该方法提供连续的内存块(> 4 GiB)。 This method should work on Mono as well as on Microsoft .NET. 此方法在Mono以及Microsoft .NET上均应适用。 It's no problem if this memory is unmanaged. 如果此内存不受管理,那没有问题。

Linux: Linux的:
I think calling mmap by DllImport is a good choice for Mono. 我认为DllImport调用mmap是Mono的不错选择。

Windows: 视窗:
I found several method's like HeapAlloc, AllocHGlobal, ..., but none of them seem to provide a 64 bit size parameter. 我发现了几种方法,例如HeapAlloc,AllocHGlobal,...,但是似乎都没有提供64位大小的参数。

There is also a method to enable large object for the GC. 还有一种为GC启用大对象的方法。 Are these objects contiguous? 这些对象是连续的吗?

Marshal.AllocHGlobal() has an IntPtr version, which can support 64-bit values. Marshal.AllocHGlobal()具有IntPtr版本,可以支持64位值。

What makes you say it doesn't. 是什么让你说没有。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM