Exemplo n.º 1
0
        public unsafe void StackallocTest4()
        {
            const int    bufferSize = 4;
            sbyte *      sample     = stackalloc sbyte[bufferSize];
            SBytePointer pointer    = new SBytePointer(sample);

            sbyte[] results = new sbyte[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);
            }
        }
Exemplo n.º 2
0
        public void _memccpyTest()
        {
            GlobalHeapAnsiString string1 = new GlobalHeapAnsiString("The quick brown dog jumps over the lazy fox");
            GlobalHeapAnsiString buffer  = new GlobalHeapAnsiString(61);
            SBytePointer         pdest   = new SBytePointer();

            Console.Write("Function: _memccpy 60 characters or to character 's'\n");
            Console.Write("Source: {0}\n", string1.ToString());

            pdest = msvcrt._memccpy(buffer, string1, 's', 60u);
            pdest.SetData(0);

            Console.Write("Result: {0}\n", buffer.ToString());
            Console.Write("Length: {0} characters\n", msvcrt.strlen(buffer.Address));

            Assert.AreEqual("The quick brown dog jumps over the lazy fox", string1.ToString());
            Assert.AreEqual("The quick brown dog jumps", buffer.ToString());
            Assert.AreEqual(25u, (uint)msvcrt.strlen(buffer.Address));

            string1.Dispose();
            buffer.Dispose();
            pdest = null;
        }