示例#1
0
        /// <summary>
        /// Sets buffers to a specified value
        /// </summary>
        /// <remarks>
        /// Sets the first length values of dest to the value "c".
        /// Make sure that the destination buffer has enough room for at least length characters.
        /// </remarks>
        /// <param name="dest">Destination pointer.</param>
        /// <param name="c">Value to set.</param>
        /// <param name="length">Number of bytes to set.</param>
        public static void Set(BufferBase dest, byte c, int length)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var ptr = dest.ToBytePointer();

                for (var i = 0; i < length; i++)
                {
                    ptr[i] = c;
                }
            }
        }
示例#2
0
文件: Buffer.cs 项目: bostich83/axiom
        public override void Copy(BufferBase src, int srcOffset, int destOffset, int length)
        {
            base.Copy(src, srcOffset, destOffset, length);

            unsafe
            {
                if (src is ManagedBuffer)
                {
                    Marshal.Copy((src as ManagedBuffer).Buf, (src as ManagedBuffer).IdxPtr + srcOffset,
                                 (IntPtr)(this.PtrBuf + destOffset), length);
                }
                else if (src is UnsafeBuffer)
                {
                    var pSrc  = src.ToBytePointer();
                    var pDest = this.ToBytePointer();

                    //Following code snippet was taken from http://msdn.microsoft.com/en-us/library/28k1s2k6(v=vs.80).aspx
                    var ps = pSrc + srcOffset;
                    var pd = pDest + destOffset;

                    // Loop over the count in blocks of 4 bytes, copying an integer (4 bytes) at a time:
                    for (var i = 0; i < length / 4; i++)
                    {
                        *((int *)pd) = *((int *)ps);
                        pd          += 4;
                        ps          += 4;
                    }

                    // Complete the copy by moving any bytes that weren't moved in blocks of 4:
                    for (var i = 0; i < length % 4; i++)
                    {
                        *pd = *ps;
                        pd++;
                        ps++;
                    }
                }
            }
        }