예제 #1
0
 static void Main(string[] args)
 {
     Slicing.Run();
     MemoryAndOwnership.Run();
     UnmanagedHeap.Run();
     StackAndHeap.Run();
     RefStructs.Run();
     UsageOfMySpan.Run();
 }
예제 #2
0
        static void Main(string[] args)
        {
            using (var pool = new UnmanagedHeap <Quote>(1000))
            {
                using (var quote = pool.Allocate())
                {
                    Console.WriteLine("quote: {0}", quote.GetCurrent());
                }
            }

            Console.ReadKey();
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var heap = new UnmanagedHeap <Customer>(50000);

            Console.ReadKey();

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < 50000; i++)
            {
                var obj = heap.AllocatePure();
            }
            var pureAllocTicks = sw.ElapsedTicks;

            Console.WriteLine("Ctor call via reflection (on already allocated memory): {0}", pureAllocTicks);
            heap.Reset();

            sw = Stopwatch.StartNew();
            for (int i = 0; i < 50000; i++)
            {
                var obj = heap.Allocate();
            }
            var ctorRedirTicks = sw.ElapsedTicks;

            Console.WriteLine("Ctor call via method body ptr redirection: {0}", ctorRedirTicks);

            sw = Stopwatch.StartNew();
            for (int i = 0; i < 50000; i++)
            {
                var obj = new Customer(123);
            }
            var newObjTicks = sw.ElapsedTicks;

            Console.WriteLine("pure allocation in managed memory: {0}", newObjTicks);
            Console.WriteLine("ctor Redirection / Refl ctor call: {0} (higher is faster)", (float)pureAllocTicks / ctorRedirTicks);
            Console.WriteLine("ctor Redirection / newobj:         {0} (higher is faster)", (float)newObjTicks / ctorRedirTicks);
            Console.WriteLine("newobj / Refl ctor call:           {0} (higher is faster)", (float)pureAllocTicks / newObjTicks);

            Console.ReadKey();
        }