I'm experiencing an unexpected behaviour while running some very simple code.
First of all I'm using Visual Studio 2015 on a i7-4770 CPU, 32Gb memory (22,6 free)
My sample code:
int length = 10;
for (int i = 0; i < length; i++)
{
int j = i;
//ThreadPool.QueueUserWorkItem(ThreadProc_CLR, j);
Task.Factory.StartNew(() => { ThreadProc_CLR(j); });
}
public void ThreadProc_CLR(object parameter)
{
int i = Convert.ToInt32(parameter);
byte[] data = new byte[1000000000];
new Random().NextBytes(data);
System.Security.Cryptography.SHA1.Create().ComputeHash(data);
}
What I do not understand is why if I run my code using
- Platform Target: Any CPU
- Prefer 32-bit checked
I get a System.OutOfMemoryException after allocating the byte[] buffer for the 3rd or 4th time
If I uncheck "Prefer 32-bit" everything works smoothly. I've googled around looking for any docs explaining possible limitations but I haven't found any.