示例#1
0
    public static int Main()
    {
        int[] arr = new int[1000];
        GCHandle[] arrhandle = new GCHandle[10000]; // array of handles to the same object
        IntPtr[] oldaddress = new IntPtr[10000];        // store old addresses
        IntPtr[] newaddress = new IntPtr[10000];        // store new addresses

        for (int i = 0; i < 10000; i++)
        {
            arrhandle[i] = GCUtil.Alloc(arr, GCHandleType.Pinned);
            oldaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        for (int i = 0; i < 10000; i++)
        {
            newaddress[i] = GCUtil.AddrOfPinnedObject(arrhandle[i]);
        }

        for (int i = 0; i < 10000; i++)
        {
            if (oldaddress[i] != newaddress[i])
            {
                Console.WriteLine("Test failed");
                return 1;
            }
        }

        Console.WriteLine("Test passed");
        return 100;
    }
示例#2
0
    public static int Main()
    {
        int    i = 10;
        Object temp1, temp2;

        GCHandle handle = GCUtil.Alloc(i, GCHandleType.Pinned);


        temp1 = GCUtil.GetTarget(handle);
        Console.WriteLine(temp1);
        GC.Collect();
        GC.WaitForPendingFinalizers();

        temp2 = GCUtil.GetTarget(handle);
        Console.WriteLine(temp2);

        if (temp1 == temp2)
        {
            Console.WriteLine("Test passed");
            return(100);
        }
        else
        {
            Console.WriteLine("Test failed");
            return(1);
        }
    }
示例#3
0
    public static int Main()
    {
        float[]  arr     = new float[100];
        GCHandle handle1 = GCUtil.Alloc(arr, GCHandleType.Pinned);
        GCHandle handle2 = GCUtil.Alloc(arr, GCHandleType.Normal);

        IntPtr oldaddr, newaddr;

        oldaddr = GCUtil.AddrOfPinnedObject(handle1);
        Console.WriteLine("Address of obj: {0}", oldaddr);

        GC.Collect();
        GC.WaitForPendingFinalizers();

        //			handle1.Free();		// arr should only have normal handle now
        GCUtil.Free(ref handle1);
        GC.Collect();
        GC.WaitForPendingFinalizers();

        GC.Collect();
        GC.WaitForPendingFinalizers();

        try
        {
            Console.WriteLine("Address of obj: {0}", handle1.AddrOfPinnedObject());
        }
        catch (Exception e)
        {
            Console.WriteLine("Caught: " + e);
        }

        arr = null;
        GC.Collect();

        // Pinning the arr again..it should have moved
        GCHandle handle3 = GCUtil.Alloc(arr, GCHandleType.Pinned);

        newaddr = GCUtil.AddrOfPinnedObject(handle3);

        Console.WriteLine("Address of obj: {0}", newaddr);

        if (oldaddr == newaddr)
        {
            Console.WriteLine("Test failed!");
            return(1);
        }
        else
        {
            Console.WriteLine("Test passed!");
            return(100);
        }
    }
示例#4
0
    public static int Main()
    {
        CreateAndReleaseFinalizable();
        TestFramework.LogInformation("First Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        GC.Collect();
        GC.WaitForPendingFinalizers();
        TestFramework.LogInformation("Second Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        GCUtil.FreePins();

        TestFramework.LogInformation("Test passed");
        return(100);
    }
示例#5
0
    public static int Main()
    {
        Console.WriteLine("First Alloc");
        GCUtil.Alloc(1024 * 1024 * 4, 30);
        GCUtil.FreeNonPins();
        GC.Collect();

        Console.WriteLine("Second Alloc");
        GCUtil.Alloc(1024 * 1024 * 4, 50);
        GCUtil.FreeNonPins();
        GC.Collect();
        GCUtil.FreePins();

        Console.WriteLine("Test passed");
        return(100);
    }
示例#6
0
    public static int Main()
    {
        Test t = new Test();

        TestFramework.LogInformation("First Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        t = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        TestFramework.LogInformation("Second Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        GCUtil.FreePins();

        TestFramework.LogInformation("Test passed");
        return(100);
    }
示例#7
0
    public static int Main()
    {
        TestFramework.LogInformation("First Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        GCUtil.FreeNonPins();
        GC.Collect();

        TestFramework.LogInformation("Second Alloc");
        GCUtil.Alloc(1024 * 1024, 50);
        GCUtil.FreeNonPins();
        GC.Collect();

        GCUtil.FreePins();

        TestFramework.LogInformation("Test passed");
        return(100);
    }
示例#8
0
    public static int Main()
    {
        Object[] arr = new Object[100];

        try
        {
            GCHandle handle1 = GCUtil.Alloc(arr, GCHandleType.Pinned);
        }
        catch (Exception e)
        {
            Console.WriteLine("Caught: {0}", e);
            Console.WriteLine("Test passed");
            return(100);
        }

        Console.WriteLine("Test failed");
        return(1);
    }
示例#9
0
    public static int Main()
    {
        int NUM = 2500;

        int[][]    arr    = new int[NUM][];
        GCHandle[] handle = new GCHandle[NUM];

        IntPtr[] oldaddr = new IntPtr[NUM];

        for (int i = 0; i < NUM; i++)
        {
            arr[i]     = new int[NUM];
            handle[i]  = GCUtil.Alloc(arr[i], GCHandleType.Pinned);
            oldaddr[i] = GCUtil.AddrOfPinnedObject(handle[i]);
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        for (int i = 0; i < NUM; i++)
        {
            if (GCUtil.AddrOfPinnedObject(handle[i]) != oldaddr[i])
            {
                Console.WriteLine("Test failed!");
                return(1);
            }
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        for (int i = 0; i < NUM; i++)
        {
            if (handle[i].IsAllocated != true)
            {
                Console.WriteLine("Test failed!");
                return(1);
            }
        }

        Console.WriteLine("Test passed!");
        return(100);
    }
示例#10
0
    public static int Main()
    {
        int[]    arr    = new int[100];
        GCHandle handle = GCUtil.Alloc(arr, GCHandleType.Pinned);
        GCHandle hhnd   = GCUtil.Alloc(handle, GCHandleType.Normal);

        GC.Collect();
        GC.WaitForPendingFinalizers();

        Console.WriteLine("Address of obj: {0}", GCUtil.AddrOfPinnedObject(handle));
        try
        {
            Console.WriteLine("Address of handle {0}", GCUtil.AddrOfPinnedObject(hhnd));
        }
        catch (Exception e)
        {
            Console.WriteLine("Caught: {0}", e.ToString());
            Console.WriteLine("Test passed");
            return(100);
        }

        return(1);
    }
示例#11
0
    public static int Main()
    {
        Object[] arr            = new Object[100];
        Object   obj            = new Object();
        int      exceptionCount = 0;

        Console.WriteLine("This test should throw 2 exceptions");

        try
        {
            GCHandle handle1 = GCUtil.Alloc(arr, GCHandleType.Pinned);
        }
        catch (Exception e)
        {
            Console.WriteLine("Caught: {0}", e);
            exceptionCount++;
        }

        try
        {
            GCHandle handle2 = GCUtil.Alloc(obj, GCHandleType.Pinned);
        }
        catch (Exception e)
        {
            Console.WriteLine("Caught: {0}", e);
            exceptionCount++;
        }

        if (exceptionCount == 2)
        {
            Console.WriteLine("Test passed");
            return(100);
        }

        Console.WriteLine("Test failed");
        return(1);
    }