fCraft.BufferUtil.MemSet C# (CSharp) Method

MemSet() public static method

Fills the entire given byte array with a specified byte value, as efficiently as possible.
array is null.
public static MemSet ( [ array, byte value ) : void
array [ Array to work with.
value byte Value to assign to each byte of the array.
return void
        public static void MemSet( [NotNull] this byte[] array, byte value ) {
            if( array == null ) throw new ArgumentNullException( "array" );
            byte[] rawValue = new[] { value, value, value, value, value, value, value, value };
            Int64 fillValue = BitConverter.ToInt64( rawValue, 0 );

            fixed( byte* ptr = array ) {
                Int64* dest = (Int64*)ptr;
                int length = array.Length;
                while( length >= 8 ) {
                    *dest = fillValue;
                    dest++;
                    length -= 8;
                }
                byte* bDest = (byte*)dest;
                for( byte i = 0; i < length; i++ ) {
                    *bDest = value;
                    bDest++;
                }
            }
        }

Same methods

BufferUtil::MemSet ( [ array, byte value, int startIndex, int length ) : void