Exemplo n.º 1
0
    public static void ChangePositioViaPointer()
    {
        byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 127, 255 };
        int    positionPointerByteArrayNumber = 3;

        Byte[][] positionPointerByteArrays = new Byte[positionPointerByteArrayNumber][];

        unsafe
        {
            fixed(byte *bytePtr = data)
            {
                //Scenario 1:ST - change the position via the PositionPointer
                using (var stream = new UnmanagedMemoryStream(bytePtr, data.Length, data.Length, FileAccess.ReadWrite))
                {
                    //we try positionPointerByteArrayNumber (10) different Byte[] arrays
                    for (int positionLoop = 0; positionLoop < positionPointerByteArrayNumber; positionLoop++)
                    {
                        //New Byte array
                        positionPointerByteArrays[positionLoop] = ArrayHelpers.CreateByteArray(length: 123, value: 24);
                        //change via PositionPointer
                        fixed(byte *invalidbytePtr = positionPointerByteArrays[positionLoop])
                        {
                            // not throw currently
                            stream.PositionPointer = invalidbytePtr;
                            VerifyNothingCanBeReadOrWritten(stream, data);
                        }
                    }

                    CheckStreamIntegrity(stream, data);
                }
            } // fixed
        }
    }