Example #1
0
        public unsafe void EqualityTest1()
        {
            double *sample   = stackalloc double[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();

            DoublePointer address3 = new DoublePointer(address2);

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

            DoublePointer address4 = new DoublePointer(address1);

            Console.WriteLine("DoublePointer 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());
        }
Example #2
0
        public static DoublePointer frompointer(SWIGTYPE_p_double t)
        {
            global::System.IntPtr cPtr = kdlPINVOKE.DoublePointer_frompointer(SWIGTYPE_p_double.getCPtr(t));
            DoublePointer         ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DoublePointer(cPtr, false);

            if (kdlPINVOKE.SWIGPendingException.Pending)
            {
                throw kdlPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #3
0
        public void UpgradeDoublePointer()
        {
            View.SetScoreLabelText(User.Points);
            View.UpgradeLevelLabel(7); // 7 -> DoublePointer index
            DoublePointer.Upgrade();
            const int Digits = 1;

            DoublePointer.CurrentPrice = Math.Round(DoublePointer.CurrentPrice * 100, Digits);
            View.SetButtonText(DoublePointer.CurrentPrice, 7); // 7 -> DoublePointer index
            this.UpdateInfoLabels();
        }
Example #4
0
        public unsafe void AddressTest1()
        {
            double *      sample = stackalloc double[4];
            DoublePointer a      = new DoublePointer(sample);
            DoublePointer b      = (a + 1);

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

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

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

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

            Assert.AreEqual(0, d.ToInt32() - c.ToInt32());
            Assert.False(Object.ReferenceEquals(c, d));
        }
Example #5
0
        public unsafe void StackallocTest3()
        {
            const int     bufferSize = 4;
            double *      sample     = stackalloc double[bufferSize];
            DoublePointer pointer    = new DoublePointer(sample);

            double[] results = new double[bufferSize];

            for (int i = 0; i < bufferSize; i++)
            {
                results[i] = *(sample + i) = GenerateRandomNumber();
            }

            // Pointer conversion test
            for (int i = 0; i < bufferSize; i++)
            {
                object x = results[i];
                object y = *(double *)(pointer + i);
                Console.WriteLine("[{0}] <Left: {1}> {2} <Right: {3}>", i, x, x.Equals(y) ? "==" : "<>", y);
                Assert.AreEqual(x, y);
            }
        }
Example #6
0
        public unsafe void StackallocTest4()
        {
            const int     bufferSize = 4;
            double *      sample     = stackalloc double[bufferSize];
            DoublePointer pointer    = new DoublePointer(sample);

            double[] results = new double[bufferSize];

            // SetData method
            for (int i = 0; i < bufferSize; i++)
            {
                pointer.SetData(results[i] = GenerateRandomNumber(), i);
            }

            // GetData method
            for (int i = 0; i < bufferSize; i++)
            {
                object x = results[i];
                object y = pointer.GetData(i);
                Console.WriteLine("[{0}] <Left: {1}> {2} <Right: {3}>", i, x, x.Equals(y) ? "==" : "<>", y);
                Assert.AreEqual(x, y);
            }
        }
Example #7
0
        public unsafe void StackallocTest5()
        {
            const int     bufferSize = 4;
            double *      sample     = stackalloc double[bufferSize];
            DoublePointer pointer    = new DoublePointer(sample);

            double[] results = new double[bufferSize];

            // Indexer based memory writing
            for (int i = 0; i < bufferSize; i++)
            {
                results[i] = pointer[i] = GenerateRandomNumber();
            }

            // Indexer based memory navigation
            for (int i = 0; i < bufferSize; i++)
            {
                object x = results[i];
                object y = pointer[i];
                Console.WriteLine("[{0}] <Left: {1}> {2} <Right: {3}>", i, x, x.Equals(y) ? "==" : "<>", y);
                Assert.AreEqual(x, y);
            }
        }
Example #8
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(DoublePointer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }