Marshal.WriteByte Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Yönetilmeyen belleğe tek bir bayt değeri yazar.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| WriteByte(Object, Int32, Byte) |
Geçersiz.
Belirtilen uzaklıkta yönetilmeyen belleğe tek bir bayt değeri yazar. |
| WriteByte(IntPtr, Byte) |
Yönetilmeyen belleğe tek bir bayt değeri yazar. |
| WriteByte(IntPtr, Int32, Byte) |
Belirtilen uzaklıkta yönetilmeyen belleğe tek bir bayt değeri yazar. |
WriteByte(Object, Int32, Byte)
- Kaynak:
- Marshal.CoreCLR.cs
- Kaynak:
- Marshal.CoreCLR.cs
- Kaynak:
- Marshal.CoreCLR.cs
- Kaynak:
- Marshal.CoreCLR.cs
- Kaynak:
- Marshal.CoreCLR.cs
Dikkat
WriteByte(Object, Int32, Byte) may be unavailable in future releases.
Belirtilen uzaklıkta yönetilmeyen belleğe tek bir bayt değeri yazar.
public:
static void WriteByte(System::Object ^ ptr, int ofs, System::Byte val);
[System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static void WriteByte(object ptr, int ofs, byte val);
[System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteByte(object ptr, int ofs, byte val);
[System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
public static void WriteByte(object ptr, int ofs, byte val);
public static void WriteByte(object ptr, int ofs, byte val);
[System.Security.SecurityCritical]
public static void WriteByte(object ptr, int ofs, byte val);
[<System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member WriteByte : obj * int * byte -> unit
[<System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")>]
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")>]
static member WriteByte : obj * int * byte -> unit
[<System.Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")>]
static member WriteByte : obj * int * byte -> unit
static member WriteByte : obj * int * byte -> unit
[<System.Security.SecurityCritical>]
static member WriteByte : obj * int * byte -> unit
Public Shared Sub WriteByte (ptr As Object, ofs As Integer, val As Byte)
Parametreler
- ptr
- Object
Hedef nesnenin yönetilmeyen belleğindeki temel adres.
- ofs
- Int32
Yazmadan önce parametresine ptr eklenen ek bayt uzaklığı.
- val
- Byte
Yazacak değer.
- Öznitelikler
Özel durumlar
Temel adres (ptr) artı uzaklık bayt (ofs) null veya geçersiz bir adres üretir.
ptr bir ArrayWithOffset nesnedir. Bu yöntem parametreleri kabul ArrayWithOffset etmez.
Açıklamalar
WriteByte yönetilmeyen bir C stili bayt dizisiyle doğrudan etkileşime olanak sağlayarak, öğe değerlerini ayarlamadan önce yönetilmeyen dizinin tamamını (kullanarak Marshal.Copy) ayrı bir yönetilen diziye kopyalama masrafını ortadan kaldırır.
Ayrıca bkz.
Şunlara uygulanır
WriteByte(IntPtr, Byte)
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
Yönetilmeyen belleğe tek bir bayt değeri yazar.
public:
static void WriteByte(IntPtr ptr, System::Byte val);
[System.Security.SecurityCritical]
public static void WriteByte(IntPtr ptr, byte val);
public static void WriteByte(IntPtr ptr, byte val);
[<System.Security.SecurityCritical>]
static member WriteByte : nativeint * byte -> unit
static member WriteByte : nativeint * byte -> unit
Public Shared Sub WriteByte (ptr As IntPtr, val As Byte)
Parametreler
- ptr
-
IntPtr
nativeint
Yönetilmeyen bellekte yazacak adres.
- val
- Byte
Yazacak değer.
- Öznitelikler
Özel durumlar
ptr tanınan bir biçim değildir.
-veya-
ptr, null'e eşittir.
-veya-
ptr geçersiz.
Örnekler
Aşağıdaki örnek yönetilmeyen bellek bloğu oluşturur, yönetilmeyen belleğe bir bayt yazar, yönetilmeyen bellekten bayt'ı geri okur ve yönetilmeyen belleği atmaktadır.
using System;
using System.Runtime.InteropServices;
class Example
{
static void Main(string[] args)
{
// Allocate 1 byte of unmanaged memory.
IntPtr hGlobal = Marshal.AllocHGlobal(1);
// Create a new byte.
byte b = 1;
Console.WriteLine("Byte written to unmanaged memory: " + b);
// Write the byte to unmanaged memory.
Marshal.WriteByte(hGlobal, b);
// Read byte from unmanaged memory.
byte c = Marshal.ReadByte(hGlobal);
Console.WriteLine("Byte read from unmanaged memory: " + c);
// Free the unmanaged memory.
Marshal.FreeHGlobal(hGlobal);
Console.WriteLine("Unmanaged memory was disposed.");
}
}
Imports System.Runtime.InteropServices
Module Example
Sub Main()
' Allocate 1 byte of unmanaged memory.
Dim hGlobal As IntPtr = Marshal.AllocHGlobal(1)
' Create a new byte.
Dim b As Byte = 1
Console.WriteLine("Byte written to unmanaged memory: {0}", b)
' Write the byte to unmanaged memory.
Marshal.WriteByte(hGlobal, b)
' Read byte from unmanaged memory.
Dim c As Byte = Marshal.ReadByte(hGlobal)
Console.WriteLine("Byte read from unmanaged memory: {0}", c)
' Free the unmanaged memory.
Marshal.FreeHGlobal(hGlobal)
Console.WriteLine("Unmanaged memory was disposed.")
End Sub
End Module
Açıklamalar
WriteByte yönetilmeyen bir C stili bayt dizisiyle doğrudan etkileşime olanak sağlayarak, öğe değerlerini ayarlamadan önce yönetilmeyen dizinin tamamını (kullanarak Marshal.Copy) ayrı bir yönetilen diziye kopyalama masrafını ortadan kaldırır.
Ayrıca bkz.
Şunlara uygulanır
WriteByte(IntPtr, Int32, Byte)
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
- Kaynak:
- Marshal.cs
Belirtilen uzaklıkta yönetilmeyen belleğe tek bir bayt değeri yazar.
public:
static void WriteByte(IntPtr ptr, int ofs, System::Byte val);
[System.Security.SecurityCritical]
public static void WriteByte(IntPtr ptr, int ofs, byte val);
public static void WriteByte(IntPtr ptr, int ofs, byte val);
[<System.Security.SecurityCritical>]
static member WriteByte : nativeint * int * byte -> unit
static member WriteByte : nativeint * int * byte -> unit
Public Shared Sub WriteByte (ptr As IntPtr, ofs As Integer, val As Byte)
Parametreler
- ptr
-
IntPtr
nativeint
Yönetilmeyen bellekte yazacak temel adres.
- ofs
- Int32
Yazmadan önce parametresine ptr eklenen ek bayt uzaklığı.
- val
- Byte
Yazacak değer.
- Öznitelikler
Özel durumlar
Temel adres (ptr) artı uzaklık bayt (ofs) null veya geçersiz bir adres üretir.
Örnekler
Aşağıdaki örnek, ve ReadByte yöntemlerini kullanarak WriteByte yönetilmeyen bir diziyi nasıl okuyup yazacaklarını gösterir.
static void ReadWriteByte()
{
// Allocate unmanaged memory.
int elementSize = 1;
IntPtr unmanagedArray = Marshal.AllocHGlobal(10 * elementSize);
// Set the 10 elements of the C-style unmanagedArray
for (int i = 0; i < 10; i++)
{
Marshal.WriteByte(unmanagedArray, i * elementSize, ((Byte)(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.ReadByte(unmanagedArray, i * elementSize));
}
Marshal.FreeHGlobal(unmanagedArray);
Console.WriteLine("Done. Press Enter to continue.");
Console.ReadLine();
}
Sub ReadWriteByte()
' Allocate unmanaged memory.
Dim elementSize As Integer = 1
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.WriteByte(unmanagedArray, i * elementSize, CType(i + 1, Byte))
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.ReadByte(unmanagedArray, i * elementSize))
Next i
Marshal.FreeHGlobal(unmanagedArray)
Console.WriteLine("Done. Press Enter to continue.")
Console.ReadLine()
End Sub
Açıklamalar
WriteByte yönetilmeyen bir C stili bayt dizisiyle doğrudan etkileşime olanak sağlayarak, öğe değerlerini ayarlamadan önce yönetilmeyen dizinin tamamını (kullanarak Marshal.Copy) ayrı bir yönetilen diziye kopyalama masrafını ortadan kaldırır.