I have solved the problem. Switching the target platform from "any" to x64 will allow me to successfully run this program (allocating 64 GB, which is double my physical memory limit):
byte[][] test = new byte[64][];
for (int i = 0; i < 64; i++)
test[i] = new byte[1000000000];
I'm still confused about why this issue seemingly popped out of nowhere, but there it is.
Edit: I have tried the large address aware flag, and also the gc allow large objects. It breaks the second application where i = 2 (in other words, when allocating the third set of 500 million bools, or 1.5 billion total bools, or the first 1.5 GB of RAM). This is no where near the limit of 3GB that comes as default with .NET 4.5. If you read carefully, the first application worked just fine until a day ago, when all of a sudden, it started throwing an out of memory exception when memory usage rose above 1 GB.
Edit1: Most seem to be missing the point of my question. The first application ran just fine (for a month) until yesterday, when it started throwing out of memory exceptions at appx. 1GB of memory usage. What could have changed between two days ago (when it ran fine) and yesterday, when it would no longer run?
Edit2: This question is not a duplicate. You have to realize that my application was working fine for a month until yesterday. The only change to my machine at all was upgrading FLStudio from FL 11 to FL 12. I will uninstall FL completely and see if that changes anything, but I highly doubt that it will.
To start, some background info: The problem is not a lack of memory. I have 32 GB of RAM, and am running a 64 bit version of windows. I wish the problem was that simple, if it were, I wouldn't have had to come here for help.
So I built this application:
uint arraySize = 2000000000;
uint squareRoot = Convert.ToUInt32(Math.Sqrt(arraySize));
bool[] sieveContainer = new bool[arraySize];
ulong sum = 0;
for (int baseMultiple = 2; baseMultiple < squareRoot; baseMultiple++)
{
if (sieveContainer[baseMultiple] == false)
{
for (int multiples = baseMultiple * 2; multiples < arraySize; multiples += baseMultiple)
sieveContainer[multiples] = true;
}
}
for (int j = 2; j < arraySize; j++)
{
if (sieveContainer[j] == false)
sum++;
}
This worked perfectly alright and was happy to consume about 2GB of RAM. Up until yesterday. As soon as it breaks 1GB (sometimes even .75GB) I get an out of memory exception. I started looking for potential solutions, and found that I didn't really have enough information about my problem to find one. So I built this test application:
byte[][] test = new byte[16][];
for (int i = 0; i < 16; i++)
test[i] = new byte[500000000];
Once again, at 1GB of RAM being allocated, I get a System.OutOfMemoryException error. No other information is provided. I have tried everything I can think of/find from reputable sources on the internet, and haven't been able to find a solution. (Solutions yielding no result were immediately reversed).
Why can I only use 1GB of memory for an entire application, when yesterday I could use +2GB? I haven't messed around with any settings in Visual Studio, nor have I changed anything in my machine. I ran MalwareBytes, which found nothing. I'm out of ideas, do you have any?