sbach2o -> RE: Unable to load game, out of memory. (3/30/2010 10:41:44 AM)
|
Just a (more or less random) note: The DW application is built on the .NET framework. When huge amounts of data are handled in memory, one has to be careful about the (otherwise carefree) memory handling. I've seen instances where the dynamic handling of strings reached its limit. If you try to increase a string to beyond some ~150 MB (or maybe double of that , I don't remember whether that limit was bytes or characters), you run afoul of an out of memory error. This is not the system running out of memory, but the .NET library reaching a limit for a certain operation. My guess (confirmed by the example below) is, this may also apply to other dynamic structures like certain collection types, which in turn would be a candidate for DW (I really don't think it handles strings that long). Here is a code snippet that will produce an 'out of memory exception' after using up 'only' 0.5 GB of virtual memory. I am sure one can produce examples that reach that with even less investment:
struct bla
// 160 bytes of data
{
long a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
long b1, b2, b3, b4, b5, b6, b7, b8, b9, b10;
public bla(int i)
{
a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = a10 = 0;
b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = b10 = i;
}
}
private void crashme()
{
// pre allocate a huge dump, we're interested in what happens beyond that.
Dictionary<string, bla> dump = new Dictionary<string, bla>(500000);
for (int i = 0; i < 100000000; ++i)
{
try
{
dump.Add(i.ToString(), new bla(i));
}
catch (Exception ee)
{
MessageBox.Show(this, String.Format("adding to the dump crashed at {0} with excpetion {1}", i, ee.Message));
break;
}
}
}
Edit: Better example that crashed with less memory use. In .Net applications you have to be very careful wherever huge arrays are handled that are dynamically expanded. That includes library-internal handling of arrays as it happens with string in, for example:
// string type uses a character array internally that is dynamically expanded while reading in a text file.
// Will crash beyond ~80 MB
string fileContents = File.ReadAllText("c:\hugetextfile.txt"); To 'fix' the first example, you'd need to store references in the dictionary (and its internal value array). Change 'struct' to 'class' and the app will consume practically all available memory before crashing.
|
|
|
|