static class · System.Runtime.InteropServices
Marshal
public static class Marshal
Native memory and conversions between Antril values and C data.
- Tipo
- static class
- Espacio de nombres
- System.Runtime.InteropServices
- Ensamblado
- System.Core
- Acceso
- public, static, abstract
- Archivo fuente
Interop.ant
Herencia
- Clases base
-
AnyMarshal
Métodos
bytes of native memory, zeroed (FreeHGlobal gives it back).
unsafe FreeHGlobal(void* block)
#
bytes of native memory, zeroed (FreeCoTaskMem gives it back).
unsafe FreeCoTaskMem(void* block)
#
A null-terminated UTF-8 copy of text in native memory (FreeCoTaskMem gives it back).
A null-terminated UTF-8 copy of text in native memory (FreeHGlobal gives it back).
A null-terminated UTF-16 copy of text in native memory (FreeHGlobal gives it back).
The null-terminated UTF-8 text at text (null: an empty string).
The length bytes of UTF-8 at text.
The null-terminated UTF-16 text at text (null: an empty string).
The length UTF-16 units at text.
unsafe ReadIntPtr(void* at) : void*
#
unsafe WriteIntPtr(void* at, void* value)
#
unsafe Copy<T : [i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64], numeric>(T[] source, i32 start, void* destination, i32 length)
#
Copies length elements of source from start to native memory at destination.
unsafe Copy<T : [i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64], numeric>(void* source, T[] destination, i32 start, i32 length)
#
Copies length elements from native memory at source into destination from start.
The size of a T in bytes (as C sees it).
Miembros heredados (5)
GetTypemétodo de AnyUndescribedmétodo de AnyToStringmétodo de AnyHashmétodo de Anydestroymétodo de Any
Código fuente
Marshal en Antril, descompilado a partir de su Larva HIR.
// System.Runtime.InteropServices.Marshal — System.Core (decompiled from Larva HIR)
import System;
into namespace System.Runtime.InteropServices
{
/// Native memory and conversions between Antril values and C data.
public static class Marshal
{
public:
/// `bytes` of native memory, zeroed (FreeHGlobal gives it back).
unsafe AllocHGlobal(i64 bytes) : void* => (void*)CStrings.Allocate(bytes);
unsafe FreeHGlobal(void* block)
{
CStrings.Release((u8*)block);
}
/// `bytes` of native memory, zeroed (FreeCoTaskMem gives it back).
unsafe AllocCoTaskMem(i32 bytes) : void* => (void*)CStrings.Allocate(bytes);
unsafe FreeCoTaskMem(void* block)
{
CStrings.Release((u8*)block);
}
/// A null-terminated UTF-8 copy of `text` in native memory (FreeCoTaskMem gives it back).
unsafe StringToCoTaskMemUTF8(str text) : u8* => CStrings.Utf8(text);
/// A null-terminated UTF-8 copy of `text` in native memory (FreeHGlobal gives it back).
unsafe StringToHGlobalUTF8(str text) : u8* => CStrings.Utf8(text);
/// A null-terminated UTF-16 copy of `text` in native memory (FreeHGlobal gives it back).
unsafe StringToHGlobalUni(str text) : u16* => CStrings.Utf16(new String<u16>(Unicode.ToUtf16(text)));
/// The null-terminated UTF-8 text at `text` (null: an empty string).
unsafe PtrToStringUTF8(u8* text) : str => text == (u8*)0 ? "" : PtrToStringUTF8(text, CStrings.Length8(text));
/// The `length` bytes of UTF-8 at `text`.
unsafe PtrToStringUTF8(u8* text, i32 length) : str
{
u8[] units = new u8[length];
loop (i32 i = 0..length)
units[i] = *(text + (i64)i);
return new str(units);
}
/// The null-terminated UTF-16 text at `text` (null: an empty string).
unsafe PtrToStringUni(u16* text) : str => text == (u16*)0 ? "" : PtrToStringUni(text, CStrings.Length16(text));
/// The `length` UTF-16 units at `text`.
unsafe PtrToStringUni(u16* text, i32 length) : str
{
u16[] units = new u16[length];
loop (i32 i = 0..length)
units[i] = *(text + (i64)i);
return Unicode.FromUtf16(units);
}
unsafe ReadByte(void* at) : u8 => *(u8*)at;
unsafe ReadByte(void* at, i32 offset) : u8 => *((u8*)at + (i64)offset);
unsafe ReadInt16(void* at) : i16 => *(i16*)at;
unsafe ReadInt16(void* at, i32 offset) : i16 => *(i16*)((u8*)at + (i64)offset);
unsafe ReadInt32(void* at) : i32 => *(i32*)at;
unsafe ReadInt32(void* at, i32 offset) : i32 => *(i32*)((u8*)at + (i64)offset);
unsafe ReadInt64(void* at) : i64 => *(i64*)at;
unsafe ReadInt64(void* at, i32 offset) : i64 => *(i64*)((u8*)at + (i64)offset);
unsafe ReadIntPtr(void* at) : void* => *(void**)at;
unsafe ReadIntPtr(void* at, i32 offset) : void* => *(void**)((u8*)at + (i64)offset);
unsafe WriteByte(void* at, u8 value)
{
*(u8*)at = value;
}
unsafe WriteByte(void* at, i32 offset, u8 value)
{
*((u8*)at + (i64)offset) = value;
}
unsafe WriteInt16(void* at, i16 value)
{
*(i16*)at = value;
}
unsafe WriteInt16(void* at, i32 offset, i16 value)
{
*(i16*)((u8*)at + (i64)offset) = value;
}
unsafe WriteInt32(void* at, i32 value)
{
*(i32*)at = value;
}
unsafe WriteInt32(void* at, i32 offset, i32 value)
{
*(i32*)((u8*)at + (i64)offset) = value;
}
unsafe WriteInt64(void* at, i64 value)
{
*(i64*)at = value;
}
unsafe WriteInt64(void* at, i32 offset, i64 value)
{
*(i64*)((u8*)at + (i64)offset) = value;
}
unsafe WriteIntPtr(void* at, void* value)
{
*(void**)at = value;
}
unsafe WriteIntPtr(void* at, i32 offset, void* value)
{
*(void**)((u8*)at + (i64)offset) = value;
}
/// Copies `length` elements of `source` from `start` to native memory at `destination`.
unsafe Copy<T : [i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64], numeric>(T[] source, i32 start, void* destination, i32 length)
{
T* to = (T*)destination;
loop (i32 i = 0..length)
*(to + (i64)i) = source[start + i];
}
/// Copies `length` elements from native memory at `source` into `destination` from `start`.
unsafe Copy<T : [i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64], numeric>(void* source, T[] destination, i32 start, i32 length)
{
T* from = (T*)source;
loop (i32 i = 0..length)
destination[start + i] = *(from + (i64)i);
}
/// The size of a `T` in bytes (as C sees it).
SizeOf<T>() : i32 => (i32)sizeof(T);
}
}