Ejemplo n.º 1
0
        private static void ManualTable <T>(AllocPointer <T> alloc)
        {
            bool refType = !typeof(T).IsValueType;

            ConsoleTable table =
                refType
                                        ? new ConsoleTable("Index", "Address", "Value", "Heap pointer")
                                        : new ConsoleTable("Index", "Address", "Value");

            for (int i = alloc.Start; i <= alloc.End; i++)
            {
                var addr = PointerUtils.Offset <T>(alloc.Address, i);

                if (refType)
                {
                    table.AddRow(i, Hex.ToHex(addr), alloc[i], Hex.ToHex(Marshal.ReadIntPtr(addr)));
                }
                else
                {
                    table.AddRow(i, Hex.ToHex(addr), alloc[i]);
                }
            }


            Console.WriteLine(table.ToMarkDownString());
        }
Ejemplo n.º 2
0
 private static void RandomInit(AllocPointer <string> ptr)
 {
     for (int i = 0; i < ptr.Count; i++)
     {
         ptr[i] = StringUtils.Random(10);
     }
 }
Ejemplo n.º 3
0
        /**
         * RazorSharp
         *
         * History:
         *  - RazorSharp (deci-common-c)
         *  - RazorSharpNeue
         *  - RazorCLR
         *  - RazorSharp
         *
         * RazorSharp:
         *  - RazorCommon
         *  - CompilerServices.Unsafe
         *  - RazorInvoke
         *  - Fody
         *  - MethodTimer Fody
         *
         * Test:
         *  - RazorCommon
         *  - CompilerServices.Unsafe
         *  - NUnit
         *  - BenchmarkDotNet
         *  - Fody
         *  - MethodTimer Fody
         *
         * Notes:
         *  - 32-bit is not fully supported
         *  - Most types are not thread-safe
         *
         * Goals:
         *  - Provide identical functionality of ClrMD, SOS, and Reflection
         *    but in a faster and more efficient way
         */
        public static void Main(string[] args)
        {
            /*alloc[0] = "g";
             * alloc[1] = "anime";
             * alloc[2] = "waifu";
             * alloc[3] = "animanga";
             * alloc[4] = "nyaa~";*/
            var alloc = new AllocPointer <string>(5);

            for (int i = 0; i < alloc.Count; i++)
            {
                Console.Clear();
                Console.Write("{0:T}", alloc);
                Thread.Sleep(1000);
                alloc++;
            }
        }
Ejemplo n.º 4
0
        private static void Table <T>(AllocPointer <T> ptr)
        {
            for (int i = 0; i < ptr.Count; i++)
            {
                Console.Clear();
                Console.WriteLine("{0:E}", ptr);
                Thread.Sleep(1000);
                ptr++;
            }

            Thread.Sleep(1000);

            for (int i = 0; i < ptr.Count; i++)
            {
                Console.Clear();
                Console.WriteLine("{0:E}", ptr);
                Thread.Sleep(1000);
                ptr--;
            }
        }
Ejemplo n.º 5
0
 public void Setup()
 {
     m_allocPtr = new AllocPointer <int>(ArrayLength);
 }
Ejemplo n.º 6
0
        public void Test()
        {
            var alloc = new AllocPointer <string>(5)
            {
                [0] = "g",
                [1] = "anime",
                [2] = "waifu",
                [3] = "animanga",
                [4] = "nyaa~"
            };

            Assert.That(alloc.Start, Is.EqualTo(0));
            Assert.That(alloc.End, Is.EqualTo(4));

            Assert.That(alloc.IsAllocated, Is.EqualTo(true));
            Assert.That(alloc.ElementSize, Is.EqualTo(Unsafe.SizeOf <string>()));
            Assert.That(alloc.IsNull, Is.EqualTo(false));
            Assert.That(alloc.Count, Is.EqualTo(5));
            Assert.That(alloc.IsDecayed, Is.EqualTo(false));

            // Bounds checking

            Assertion.AssertThrows <Exception>(delegate
            {
                var p = new AllocPointer <string>(5);
                p    += p.Count + 1;
            });

            Assertion.AssertThrows <Exception>(delegate
            {
                var p = new AllocPointer <string>(5);
                p    -= p.Count + 1;
            });

            Assertion.AssertThrows <Exception>(delegate
            {
                var x = alloc[-1];
            });

            Assertion.AssertThrows <Exception>(delegate
            {
                var x = alloc[alloc.Count];
            });

            Assertion.AssertThrows <Exception>(delegate
            {
                alloc++;
                var x = alloc[-2];
            });

            Assertion.AssertNoThrows <Exception>(delegate
            {
                alloc--;
                var x = alloc[0];
            });

            alloc.Dispose();

            Assert.That(alloc.IsAllocated, Is.EqualTo(false));
            Assert.That(alloc.Address, Is.EqualTo(IntPtr.Zero));
            Assert.That(alloc.Value, Is.EqualTo(default));