Init array to non zero values

  • Thread starter Thread starter Alan Chen
  • Start date Start date
A

Alan Chen

Hi,
I have a byte array which I'd like to init to all 0xFF. The array size
is passed in as a parameter. What is the best way to do it?
I can certainly do it in a loop but it is not effecient.
Thanks in advance for your input!
 
Try this

[DllImport( "kernel32.dll")]
private static extern void FillMemory( byte[] arr, int size, byte fill );

Usage -

byte [] myArray = new byte[10];

FillMemory( myArray, myArray.Length, 0xFF );
 
Thanks, it works beautifully (plus: using
System.Runtime.InteropServices;).
Since .NET base class library is designed to hide the low-level API, my
next question is do you know if there is corresponding memory management
APIs in the .NET that I can use?
 
Back
Top