Como alocar mais de MaxInteger bytes de memória em c #
Desejo alocar mais de MaxInteger bytes de memória.
Marshall.AllocHGlobal () espera um número inteiro - então não posso usar isso. Existe outro caminho?
Atualizar
Alterei a plataforma para x64 e executei o código abaixo.
myp parece ter o comprimento certo: cerca de 3,0G. Mas teimosamente "buffer" atinge o máximo de 2.1G.
Alguma idéia do porquê?
var fileStream = new FileStream(
"C:\\big.BC2",
FileMode.Open,
FileAccess.Read,
FileShare.Read,
16 * 1024,
FileOptions.SequentialScan);
Int64 length = fileStream.Length;
Console.WriteLine(length);
Console.WriteLine(Int64.MaxValue);
IntPtr myp = new IntPtr(length);
//IntPtr buffer = Marshal.AllocHGlobal(myp);
IntPtr buffer = VirtualAllocEx(
Process.GetCurrentProcess().Handle,
IntPtr.Zero,
new IntPtr(length),
AllocationType.Commit | AllocationType.Reserve,
MemoryProtection.ReadWrite);
unsafe
{
byte* pBytes = (byte*)myp.ToPointer();
var memoryStream = new UnmanagedMemoryStream(pBytes, (long)length, (long)length, FileAccess.ReadWrite);
fileStream.CopyTo(memoryStream);