This a moot question, as the amount I was allocating was wrong. It was supposed to be 400MB not 400GB... Sorry! The answers are good though.
I am trying to unit test a method of mine which throws an OutOfMemoryException if a large file is uploaded.
My problem is my unit test is also throwing this exception (for the same reasons I guess).
According to Task Manager, if I am reading the information correctly, I do have enough RAM so am not really sure why my unit test is failing in this way.
Here is the respective unit test code:
var data = new List<byte>();
for(UInt64 i = 0; i < 400ul * 1024ul * 1024ul * 1024ul; i += 65536ul)
{
data.AddRange(new byte[65536]); // <-- throws exception here when i = 536870912
}
this.UploadedFileData = data.ToArray();
I tried the following before the above code:
var data = new byte[400ul * 1024ul * 1024ul * 1024ul];
This though, results in the error: Arithmetic operation resulted in an overflow.