Marshal.SizeOf Yöntem

Tanım

Bir sınıfın yönetilmeyen boyutunu bayt cinsinden döndürür.

Aşırı Yüklemeler

SizeOf(Object)
Geçersiz.

Bir nesnenin yönetilmeyen boyutunu bayt cinsinden döndürür.

SizeOf(Type)
Geçersiz.

Yönetilmeyen bir türün boyutunu bayt cinsinden döndürür.

SizeOf<T>()

Yönetilmeyen bir türün boyutunu bayt cinsinden döndürür.

SizeOf<T>(T)

Belirtilen türde bir nesnenin yönetilmeyen boyutunu bayt cinsinden döndürür.

SizeOf(Object)

Kaynak:
Marshal.cs
Kaynak:
Marshal.cs
Kaynak:
Marshal.cs

Dikkat

SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514

Bir nesnenin yönetilmeyen boyutunu bayt cinsinden döndürür.

public:
 static int SizeOf(System::Object ^ structure);
[System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")]
public static int SizeOf (object structure);
public static int SizeOf (object structure);
[System.Runtime.InteropServices.ComVisible(true)]
public static int SizeOf (object structure);
[<System.Obsolete("SizeOf(Object) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296514")>]
static member SizeOf : obj -> int
static member SizeOf : obj -> int
[<System.Runtime.InteropServices.ComVisible(true)>]
static member SizeOf : obj -> int
Public Shared Function SizeOf (structure As Object) As Integer

Parametreler

structure
Object

Boyutu döndürülecek nesne.

Döndürülenler

Yönetilmeyen kodda belirtilen nesnenin boyutu.

Öznitelikler

Özel durumlar

structure parametresidirnull.

Örnekler

Aşağıdaki örnek yönetilen bir yapı oluşturur, yönetilmeyen belleğe aktarır ve ardından yönetilen belleğe geri aktarır. Bu örnek, SizeOf ne kadar yönetilmeyen bellek ayrılacak belirlemek için yöntemini kullanır.

using System;
using System.Runtime.InteropServices;

public struct Point
{
    public int x;
    public int y;
}

class Example
{

    static void Main()
    {

        // Create a point struct.
        Point p;
        p.x = 1;
        p.y = 1;

        Console.WriteLine("The value of first point is " + p.x + " and " + p.y + ".");

        // Initialize unmanged memory to hold the struct.
        IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(p));

        try
        {

            // Copy the struct to unmanaged memory.
            Marshal.StructureToPtr(p, pnt, false);

            // Create another point.
            Point anotherP;

            // Set this Point to the value of the
            // Point in unmanaged memory.
            anotherP = (Point)Marshal.PtrToStructure(pnt, typeof(Point));

            Console.WriteLine("The value of new point is " + anotherP.x + " and " + anotherP.y + ".");
        }
        finally
        {
            // Free the unmanaged memory.
            Marshal.FreeHGlobal(pnt);
        }
    }
}
Imports System.Runtime.InteropServices



Public Structure Point
    Public x As Integer
    Public y As Integer
End Structure


Module Example


    Sub Main()

        ' Create a point struct.
        Dim p As Point
        p.x = 1
        p.y = 1

        Console.WriteLine("The value of first point is " + p.x.ToString + " and " + p.y.ToString + ".")

        ' Initialize unmanged memory to hold the struct.
        Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(p))

        Try

            ' Copy the struct to unmanaged memory.
            Marshal.StructureToPtr(p, pnt, False)

            ' Create another point.
            Dim anotherP As Point

            ' Set this Point to the value of the 
            ' Point in unmanaged memory. 
            anotherP = CType(Marshal.PtrToStructure(pnt, GetType(Point)), Point)

            Console.WriteLine("The value of new point is " + anotherP.x.ToString + " and " + anotherP.y.ToString + ".")

        Finally
            ' Free the unmanaged memory.
            Marshal.FreeHGlobal(pnt)
        End Try

    End Sub
End Module

Açıklamalar

Bu yöntem, başvuru türü veya kutulu değer türü olabilecek bir yapı örneğini kabul eder. Düzen sıralı veya açık olmalıdır.

Döndürülen boyut yönetilmeyen nesnenin boyutudur. Bir nesnenin yönetilmeyen ve yönetilen boyutları farklılık gösterebilir. Karakter türleri için boyut, bu sınıfa CharSet uygulanan değerden etkilenir.

ve AllocCoTaskMem yöntemlerini kullanarak AllocHGlobal ne kadar yönetilmeyen bellek ayrılabileceğini belirlemek için yöntemini kullanabilirsinizSizeOf.

Ayrıca bkz.

Şunlara uygulanır

SizeOf(Type)

Kaynak:
Marshal.cs
Kaynak:
Marshal.cs
Kaynak:
Marshal.cs

Dikkat

SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515

Yönetilmeyen bir türün boyutunu bayt cinsinden döndürür.

public:
 static int SizeOf(Type ^ t);
[System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")]
public static int SizeOf (Type t);
public static int SizeOf (Type t);
[<System.Obsolete("SizeOf(Type) may be unavailable in future releases. Instead, use SizeOf<T>(). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296515")>]
static member SizeOf : Type -> int
static member SizeOf : Type -> int
Public Shared Function SizeOf (t As Type) As Integer

Parametreler

t
Type

Boyutu döndürülecek olan tür.

Döndürülenler

Yönetilmeyen kodda belirtilen türün boyutu.

Öznitelikler

Özel durumlar

t parametresi genel bir tür tanımıdır.

t parametresidirnull.

Örnekler

Aşağıdaki örnekte yönteminin çağrılması gösterilmektedir SizeOf . Bu kod örneği, sınıfı için Marshal sağlanan daha büyük bir örneğin parçasıdır.

// Demonstrate the use of the SizeOf method of the Marshal
// class.
Console::WriteLine("Number of bytes needed by a Point object: {0}",
    Marshal::SizeOf(Point::typeid));
Point point;
Console::WriteLine("Number of bytes needed by a Point object: {0}",
    Marshal::SizeOf(point));
// Demonstrate the use of the SizeOf method of the Marshal class.
Console.WriteLine("Number of bytes needed by a Point object: {0}",
    Marshal.SizeOf(typeof(Point)));
Point p = new Point();
Console.WriteLine("Number of bytes needed by a Point object: {0}",
    Marshal.SizeOf(p));
' Demonstrate the use of the SizeOf method of the Marshal class.
Console.WriteLine("Number of bytes needed by a Point object: {0}", Marshal.SizeOf(GetType(Point)))
Dim p As New Point()
Console.WriteLine("Number of bytes needed by a Point object: {0}", Marshal.SizeOf(p))

Açıklamalar

Bir yapınız olmadığında bu yöntemi kullanabilirsiniz. Düzen sıralı veya açık olmalıdır.

Döndürülen boyut, yönetilmeyen türün boyutudur. Bir nesnenin yönetilmeyen ve yönetilen boyutları farklılık gösterebilir. Karakter türleri için boyut, bu sınıfa CharSet uygulanan değerden etkilenir.

Ayrıca bkz.

Şunlara uygulanır

SizeOf<T>()

Kaynak:
Marshal.cs
Kaynak:
Marshal.cs
Kaynak:
Marshal.cs

Yönetilmeyen bir türün boyutunu bayt cinsinden döndürür.

public:
generic <typename T>
 static int SizeOf();
public static int SizeOf<T> ();
static member SizeOf : unit -> int
Public Shared Function SizeOf(Of T) () As Integer

Tür Parametreleri

T

Boyutu döndürülecek olan tür.

Döndürülenler

Genel tür parametresi tarafından T belirtilen türün bayt cinsinden boyutu.

Açıklamalar

Bir yapınız olmadığında bu yöntemi kullanabilirsiniz. Düzen sıralı veya açık olmalıdır.

Döndürülen boyut, yönetilmeyen türün boyutudur. Bir nesnenin yönetilmeyen ve yönetilen boyutları farklılık gösterebilir. Karakter türleri için boyut, bu sınıfa CharSet uygulanan değerden etkilenir.

Şunlara uygulanır

SizeOf<T>(T)

Kaynak:
Marshal.cs
Kaynak:
Marshal.cs
Kaynak:
Marshal.cs

Belirtilen türde bir nesnenin yönetilmeyen boyutunu bayt cinsinden döndürür.

public:
generic <typename T>
 static int SizeOf(T structure);
public static int SizeOf<T> (T structure);
static member SizeOf : 'T -> int
Public Shared Function SizeOf(Of T) (structure As T) As Integer

Tür Parametreleri

T

structure parametresinin türü.

Parametreler

structure
T

Boyutu döndürülecek nesne.

Döndürülenler

Yönetilmeyen kodda belirtilen nesnenin bayt cinsinden boyutu.

Özel durumlar

structure parametresidirnull.

Açıklamalar

Bu yöntem, başvuru türü veya kutulu değer türü olabilecek bir yapı örneğini kabul eder. Düzen sıralı veya açık olmalıdır.

Döndürülen boyut yönetilmeyen nesnenin boyutudur. Bir nesnenin yönetilmeyen ve yönetilen boyutları farklılık gösterebilir. Karakter türleri için boyut, bu sınıfa CharSet uygulanan değerden etkilenir.

ve AllocCoTaskMem yöntemlerini kullanarak AllocHGlobal ne kadar yönetilmeyen bellek ayrılabileceğini belirlemek için yöntemini kullanabilirsinizSizeOf<T>(T).

Şunlara uygulanır