When I declare a new byte array, the memory usage does not increase.
byte[] test = new[1024*100];
Its only after I iterate through each byte does it actually start taking ram.
How can I make it actually commit the memory without having to use it first?
I am using this as a test with a try catch block to see if it will fail to allocate the memory, thus telling me that my application is out of ram and it should not attempt to allocate any new objects.
Edit: since the objects I am going to be allocating are used with the garbage collector and stack, I don't want to allocate using malloc since it might succeed there, but fail when trying to allocate a new managed object.
Made a function that will attempt to actually allocate the memory I specify (and throw an exception if its not possible rather than lie about it) and will be instantly collected by the garbage collector if it succeeds.
bool IsMemoryAvailable(int amount)
{
int size = (int)Math.Sqrt(amount) / 2;
try
{
using (Bitmap bmpTest = new Bitmap(size, size))
{
}
GC.Collect();
return true;
}
catch(Exception x)
{
return false;
}
}