-3

Okay so I'm experimenting and Id like to know a few things. First I"ll paste the code to my base object class. So you get an idea.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P_Object
{
    class base_object
    {
        string pronoun_name;
        string noun_name;
        string internal_name;
        string internal_id;
        Dictionary<string, string> relations = new Dictionary<string, string>();

    }
}

Here is what is crashing it.

In another class as part of it's definition I have:

private base_object[] objects1=new base_object[99999999];
private base_object[] objects2 = new base_object[99999999];
private base_object[] objects3 = new base_object[99999999];
private base_object[] objects4 = new base_object[99999999];
private base_object[] objects5 = new base_object[99999999];
private base_object[] objects6 = new base_object[99999999];
private base_object[] objects7 = new base_object[99999999];
private base_object[] objects8 = new base_object[99999999];
private base_object[] objects9 = new base_object[99999999];
private base_object[] objects10 = new base_object[99999999];
private base_object[] objects11 = new base_object[99999999];
private base_object[] objects12 = new base_object[99999999];
private base_object[] objects13 = new base_object[99999999];
private base_object[] objects14 = new base_object[99999999];
private base_object[] objects15 = new base_object[99999999];
private base_object[] objects16 = new base_object[99999999];
private base_object[] objects17 = new base_object[99999999];
private base_object[] objects18 = new base_object[99999999];
private base_object[] objects19 = new base_object[99999999];
private base_object[] objects20 = new base_object[99999999];
private base_object[] objects21 = new base_object[99999999];
private base_object[] objects22 = new base_object[99999999];
private base_object[] objects23 = new base_object[99999999];
private base_object[] objects24 = new base_object[99999999];
private base_object[] objects25 = new base_object[99999999];

My main goal is to test how far I can push C# before it crashes on me in terms of how much array memory do I have to work with... the only reason for the crash I can think of is that I've ran out of memory somehow? :/

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Remmie
  • 47
  • 10

2 Answers2

0

There might be compiler enforced limitation on this, but how far you can push c# in terms of memory usage is a function of your hardware. More memory allows for more arrays etc. It's hard to be more specific based on the question.

TGH
  • 38,769
  • 12
  • 102
  • 135
0

Why does this matter to you? What exactly are you trying to validate here?

All platforms have limited memory capabilities. And Looking at your code, I can't imagine a single scenario where you would ever need to put that many things on the stack at one time.

So basically, with each objects array you have 99999999 null pointers reserved in memory. And in a 64 bit target, that's 99999999 * 8 bytes of memory being reserved per array. Which is 799,999,992 so baqsically almost a gig per object. Then you did that 25 times, so 799,999,992 * 25 = 19,999,999,800 19.9 Gig.... On a system that probably has between 4 and 16 gig of ram.

Of course it crashes.

And I said null pointers, because you initialize the arrays, but you never store anything to any of the indexes. C# doesn't instantiate your object base_object for you when you define an array of them. Each array element will end up pointing to the address of w/e your object is created. So at their current state they are just null pointers with no base_objects initialized.

Ryan Mann
  • 5,178
  • 32
  • 42
  • Oh really? That makes sense. So I basically have almost 20 GB of null objects. Wow. o.o I've really done it. LOL Omg. I should have known. – Remmie May 26 '14 at 04:50