Exemplo n.º 1
0
        public unsafe void EqualityTest1()
        {
            sbyte *sample   = stackalloc sbyte[4];
            int    checksum = 0;

            int address1 = (int)sample;

            Console.WriteLine("Original Address: {0:X}", address1);
            checksum += address1;

            IntPtr address2 = new IntPtr(sample);

            Console.WriteLine("IntPtr Address: {0:X}", address2.ToInt32());
            checksum += address2.ToInt32();

            SBytePointer address3 = new SBytePointer(address2);

            Console.WriteLine("SBytePointer Address (from IntPtr): {0:X}", address3.ToInt32());
            checksum += address3.ToInt32();

            SBytePointer address4 = new SBytePointer(address1);

            Console.WriteLine("SBytePointer Address (from Int32): {0:X}", address4.ToInt32());
            checksum += address4.ToInt32();

            int checksumDigest = checksum / 4;

            Assert.AreEqual(checksumDigest, address1);
            Assert.AreEqual(checksumDigest, address2.ToInt32());
            Assert.AreEqual(checksumDigest, address3.ToInt32());
            Assert.AreEqual(checksumDigest, address4.ToInt32());
        }
Exemplo n.º 2
0
        public unsafe void AddressTest1()
        {
            sbyte *      sample = stackalloc sbyte[4];
            SBytePointer a      = new SBytePointer(sample);
            SBytePointer b      = (a + 1);

            Console.WriteLine("Address offset: {0}", b.ToInt32() - a.ToInt32());

            Assert.AreEqual(sizeof(sbyte), b.ToInt32() - a.ToInt32());
            Assert.False(Object.ReferenceEquals(a, b));

            // xPlatform's typed pointers are value type.
            SBytePointer c = new SBytePointer(sample + 1);
            SBytePointer d = (++c);

            Console.WriteLine("Address offset: {0}", d.ToInt32() - c.ToInt32());

            Assert.AreEqual(0, d.ToInt32() - c.ToInt32());
            Assert.False(Object.ReferenceEquals(c, d));
        }