64-Bit VB.NET Allocating > 2GB of RAM (.NET bug?)

前端 未结 4 1158
日久生厌
日久生厌 2021-01-13 11:01

I have a 64 bit VB.NET application and want to allocate a buffer > 2GB in size.

In the following code both the \"new\" and the \"ReDim\" throw an \"OverflowException

相关标签:
4条回答
  • 2021-01-13 11:23

    I think the UnmanagedMemoryStream does what you need. MSDN doc for UnmanagedMemoryStream

    I think it's a bad idea, to allocate a huge chunk of memory in a garbage collected environment, since most garbage collectors are optimized for small & short lived object. So using raw memory is generally a better and more performant solution for very large objects.

    0 讨论(0)
  • 2021-01-13 11:30

    Apparently it is not possible to allocate more than 2GB even under 64 bit .net application running on a 64 bit OS.

    I find this to be very disappointing and completely without regard for what 64 bit applications and OSs are made for. I am dealing with gigantic images and would like to be able to work with the raw bytes all in RAM at once. Now I have to implement paging algorithms to limit the chunks to 2GB.

    Hey Microsoft, hows abouts you fix this in the coming .NET release? Yes, I said fix. That's because it's broken. How do you expect 64 bit applications to take off when you do stupid things like this. (Can you tell that I am annoyed.) Thanks for listening.

    Link

    http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx

    0 讨论(0)
  • 2021-01-13 11:30

    You may have to use memory mapped files for this, take a look at the MapViewOfFile function.

    0 讨论(0)
  • 2021-01-13 11:37

    The following works [in theory] (C# syntax):

    Array.CreateInstance(typeof(int[]), 0L);
    

    Edit: Make a type with a fixed-size allocated array of 1GB arrays. You can re-index in the Item property via a shift.

    0 讨论(0)
提交回复
热议问题