Método Marshal.ReadInt64 (IntPtr)
Publicado: noviembre de 2016
Lee un entero de 64 bits con signo de la memoria no administrada.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)
Sintaxis
[SecurityCriticalAttribute]
public static long ReadInt64(
IntPtr ptr
)
public:
[SecurityCriticalAttribute]
static long long ReadInt64(
IntPtr ptr
)
[<SecurityCriticalAttribute>]
static member ReadInt64 :
ptr:nativeint -> int64
<SecurityCriticalAttribute>
Public Shared Function ReadInt64 (
ptr As IntPtr
) As Long
Parámetros
ptr
Type: System.IntPtrDirección en la memoria no administrada desde la que se va a leer.
Valor devuelto
Type: System.Int64
Entero de 64 bits con signo leído de la memoria no administrada.
Excepciones
Exception | Condition |
---|---|
AccessViolationException | ptr no es un formato reconocido. O bien El valor de ptr es null. O bien ptr no es válido. |
Comentarios
ReadInt64 tiene un desplazamiento implícito de 0. Este método permite la interacción directa con un estilo de C no administrado Int64 matriz, elimina el gasto de copiar toda una matriz no administrada (mediante Marshal.Copy) a una matriz administrada distinta antes de leer los valores de sus elementos.
Se admite la lectura desde ubicaciones de memoria desalineadas.
Ejemplos
En el ejemplo siguiente se muestra cómo leer y escribir en una matriz no administrada mediante el ReadInt64 y WriteInt64 métodos.
static void ReadWriteInt64()
{
// Allocate unmanaged memory.
int elementSize = 8;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteInt64(unmanagedArray, i * elementSize, ((Int64)(i + 1)));
}
Console.WriteLine("Unmanaged memory written.");
Console.WriteLine("Reading unmanaged memory:");
// Print the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Console.WriteLine(Marshal.ReadInt64(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteInt64()
' Allocate unmanaged memory.
Dim elementSize As Integer = 8
Dim unmanagedArray As IntPtr = Marshal.AllocHGlobal(10 * elementSize)
' Set the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Marshal.WriteInt64(unmanagedArray, i * elementSize, CType(i + 1, Int64))
Next i
Console.WriteLine("Unmanaged memory written.")
Console.WriteLine("Reading unmanaged memory:")
' Print the 10 elements of the C-style unmanagedArray
For i As Integer = 0 To 9
Console.WriteLine(Marshal.ReadInt64(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
En el ejemplo siguiente se muestra cómo utilizar el ReadInt64 método para leer el valor de no administrado __int64 variable.
using namespace System;
using namespace System::Runtime::InteropServices;
void main()
{
// Create an unmanaged __int64.
__int64 myVal = 42;
// Read the value as a managed Int64.
Int64 ^ myManagedVal = Marshal::ReadInt64((IntPtr) &myVal);
// Display the value to the console.
Console::WriteLine(myManagedVal);
}
Seguridad
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Información de versión
Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1
Ver también
Copy
ReadInt64 Sobrecarga
Clase Marshal
Espacio de nombres System.Runtime.InteropServices
Volver al principio