Пример #1
0
        static void GcTest()
        {
            // Precondition: we're the first to allocate, and thus pinned at &DarkAlloc.heap[0]

            Console.WriteLine("Constructing object on heap");

            Test test = DarkAlloc.Alloc <Test>(5);

            test = null; // mark the reference up for GC

            Console.WriteLine("Triggering a garbage collection");

            // Trigger a GC
            System.GC.Collect();

            Console.WriteLine("Getting a new object reference");

            // Get a new object reference from the heap, pointing to the same object
            test = DarkAlloc.FromPtr <Test>(DarkAlloc.HeapStart);

            Console.WriteLine("Calling Print on it");

            // Do stuff with it
            test.Print();
        }
Пример #2
0
        static void Main(string[] args)
        {
            GcTest();
            Console.WriteLine("\n========\n");

            Test test  = DarkAlloc.Alloc <Test>(5);
            Test test2 = DarkAlloc.Alloc <Test>(DarkAlloc.Alloc <Foo>());

            test.Print();
            Console.WriteLine("x = {0}", test.x);

            Console.ReadKey(true);
        }