Exemplo n.º 1
0
 public static unsafe void NonGCHeap(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i % giveOutEveryN == 0)
         {
             IntPtr mem = Marshal.AllocHGlobal(sizeof(int) * 5);
             Marshal.WriteInt32(new IntPtr(mem.ToInt32() + sizeof(int) * 0), ioo.a);
             Marshal.WriteInt32(new IntPtr(mem.ToInt32() + sizeof(int) * 1), ioo.b);
             Marshal.WriteInt32(new IntPtr(mem.ToInt32() + sizeof(int) * 2), ioo.c);
             Marshal.WriteInt32(new IntPtr(mem.ToInt32() + sizeof(int) * 3), ioo.d);
             Marshal.WriteInt32(new IntPtr(mem.ToInt32() + sizeof(int) * 4), ioo.e);
             al.Add(mem);
         }
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     foreach (IntPtr mem in al)
     {
         Marshal.FreeHGlobal(mem);
     }
     al.Clear();
     System.GC.Collect();
 }
Exemplo n.º 2
0
 public static void AllocationOnly(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     al.Clear();
     System.GC.Collect();
 }
Exemplo n.º 3
0
 public static void NoPinEnd(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i > ((numberIterations - numberIterations / giveOutEveryN) - 1))
         {
             al.Add(ioo);
         }
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     al.Clear();
     System.GC.Collect();
 }
Exemplo n.º 4
0
 public static void TempGCHandle(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i % giveOutEveryN == 0)
         {
             al.Add(GCHandle.Alloc(ioo, GCHandleType.Pinned));
             GCHandle g = (GCHandle)al[al.Count - 1];
             g.Free();
         }
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     al.Clear();
     System.GC.Collect();
 }
Exemplo n.º 5
0
 unsafe public static void TempPin(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i % giveOutEveryN == 0)
         {
             fixed(int *p = &ioo.a)
             {
                 al.Add(*p);
             }
         }
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     System.GC.Collect();
 }
Exemplo n.º 6
0
 public static void Fragment(Int32 numberIterations)
 {
     System.Collections.ArrayList al = new System.Collections.ArrayList();
     for (int i = 0; i < numberIterations; ++i)
     {
         InterOpObj ioo = new InterOpObj();
         if (i % giveOutEveryN == 0)
         {
             al.Add(GCHandle.Alloc(ioo, GCHandleType.Pinned));
         }
         if (i % runGCEveryN == 0)
         {
             System.GC.Collect();
         }
     }
     foreach (GCHandle g in al)
     {
         g.Free();
     }
     al.Clear();
     System.GC.Collect();
 }