[Mono-list] Unable to create more than 1000 objects.

Nicholas Frechette zeno490 at gmail.com
Fri Dec 16 20:53:49 EST 2011

Do be careful here, you are profiling 2 different scenarios here, one
with 1000 large allocations and one with 1000000 large allocations.
(an array of value types consists of 2 allocations, one for the array
object, and one for the array values, which is different from a
non-value type array where each array slot would be a further
When iterating over both, the later should have a bit more data cache
misses but shouldn't explain what you are seeing. Although, depending
on the page allocation size, you might require significantly more
virtual pages with the later test. This might account for a large part
of the time discrepancy you are seeing. While total used memory might
be the same, virtual memory used might be very different in both

Also note that typically, large object allocations aren't typical and
isn't what the GC optimizes for. In fact, in .net, large objects are
allocated in a separate heap and means they are treated a bit
differently when it comes to GC.
Not sure how mono boehm/sgen handles large objects. Unless I am
mistaken, on .net (and c++ on win32/64), large objects are >=64kb,
again, not sure on mono.

Assuming you have 20gb of free ram and you aren't hitting the swap,
IMO, none of the above should explain for the time discrepancy you are
seeing. It shouldn't take 6mins to allocate 1 million large objects.
But do keep in mind that small objects might be allocated entirely
differently. Specially when multiple threads are allocating. I might
also be wrong :)
I for one would not be surprised if there was 1 small heap per thread
+ 1 (or more) second generation heap (for all threads) + 1 large
object heap.

Btw your code doesn't compile, the Console.WriteLine line, seems truncated.


On Fri, Dec 16, 2011 at 6:19 PM, Dragony <cschmid at rapidshare.com> wrote:
> Another sgen-benchmark. The fast run takes 13 seconds, the slow run takes 6
> minutes(!). Same result, same memory consumption. I don't think its
> impossible to adjust sgen and to make it work like a charm.
> WARNING: Test run requires 20 GB of Ram, unless you adjust the values.
> using System;
> class Test {
> // fast
>  public static int blocks = 1000;
>  public static int unitsPerBlock = 1000000;
> // slow
> //  public static int blocks = 1000000;
> //  public static int unitsPerBlock = 1000;
>  public static Unit[][] units = new Unit[blocks][];
>  static public void Main () {
>    for (int i = 0; i < blocks; i++) {
>      units[i] = new Unit[unitsPerBlock];
>      for (int u = 0; u < unitsPerBlock; u++) units[i][u].val1 = 123;
>      if (i % (blocks/100) == 0)
> Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.FFFF") + "> " + (i+1) + "
> blocks need " + (GC.GetTotalMemory(false) /
>    }
>  }
> }
> struct Unit {
>  public int val1;
>  public int val2;
>  public int val3;
>  public int val4;
>  public int val5;
> }
> --
> View this message in context: http://mono.1490590.n4.nabble.com/Unable-to-create-more-than-1000-objects-tp4184397p4206704.html
> Sent from the Mono - General mailing list archive at Nabble.com.
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list

More information about the Mono-list mailing list