Marshal.Copy Method (IntPtr, Int64, Int32, Int32)
Copies data from an unmanaged memory pointer to a managed 64-bit signed integer array.
[Visual Basic] Overloads Public Shared Sub Copy( _ ByVal source As IntPtr, _ ByVal destination() As Long, _ ByVal startIndex As Integer, _ ByVal length As Integer _ ) [C#] public static void Copy( IntPtr source, long destination, int startIndex, int length ); [C++] public: static void Copy( IntPtr source, __int64 destination __gc, int startIndex, int length ); [JScript] public static function Copy( source : IntPtr, destination : long, startIndex : int, length : int );
- The memory pointer to copy from.
- The array to copy to.
- The zero-based index into the array where Copy should start.
- The number of array elements to copy.
Unmanaged, C-style arrays do not contain bounds information, which prevents the startIndex and length parameters from being validated. Thus, the unmanaged data corresponding to the source parameter populates the managed array regardless of its usefulness. You must initalize the managed array with the appropriate size before calling the Marshal.Copy method.
Note This method uses SecurityAction.LinkDemand to prevent it from being called from untrusted code; only the immediate caller is required to have SecurityPermissionAttribute.UnmanagedCode permission. If your code can be called from partially trusted code, do not pass user input to Marshal class methods without validation. For important limitations on using the LinkDemand member, see Demand vs. LinkDemand.
[Visual Basic, C#] The following example demonstrates how to copy data from an unmanaged memory pointer into a managed array.
[Visual Basic] Public Overloads Shared Sub Copy(source As IntPtr, _ destination As Long(), startIndex As Integer, length As Integer) [C#] public static void Copy(IntPtr source, long destination, int startIndex, int length);
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
.NET Framework Security:
- SecurityPermission for operating with unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode.