Copy Method (IntPtr, Int32[], Int32, Int32)

Marshal.Copy Method (IntPtr, Int32[], Int32, Int32)

.NET Framework 1.1

Copies data from an unmanaged memory pointer to a managed 32-bit signed integer array.

[Visual Basic]
Overloads Public Shared Sub Copy( _
   ByVal source As IntPtr, _
   ByVal destination() As Integer, _
   ByVal startIndex As Integer, _
   ByVal length As Integer _
public static void Copy(
 IntPtr source,
 int[] destination,
 int startIndex,
 int length
public: static void Copy(
 IntPtr source,
 int destination __gc[],
 int startIndex,
 int length
public static function Copy(
   source : IntPtr,
 destination : int[],
 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 Integer(), startIndex As Integer, length As Integer)
public static void Copy(IntPtr source, int[] 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 Language Filter 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: 

See Also

Marshal Class | Marshal Members | System.Runtime.InteropServices Namespace | Marshal.Copy Overload List | Copy

© 2015 Microsoft