Last active
April 14, 2018 07:42
-
-
Save usausa/79bb5fd09ca3e2d540d0561e7f9e6079 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe byte[] Fill(this byte[] array, int offset, int length, byte value) | |
{ | |
if ((length <= 0) || (array == null)) | |
{ | |
return array; | |
} | |
fixed (byte* pSrc = &array[offset]) | |
{ | |
*pSrc = value; | |
byte* pDst; | |
int copy; | |
for (copy = 1; copy <= length / 2; copy <<= 1) | |
{ | |
pDst = pSrc + copy; | |
Buffer.MemoryCopy(pSrc, pDst, length - copy, copy); | |
} | |
pDst = pSrc + copy; | |
Buffer.MemoryCopy(pSrc, pDst, length - copy, length - copy); | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment