static class · System.Runtime.InteropServices

Marshal

public static class Marshal

Native memory and conversions between Antril values and C data.

Kind
static class
Namespace
System.Runtime.InteropServices
Assembly
System.Core
Access
public, static, abstract
Source file
Interop.ant

Inheritance

Base classes
Any Marshal

Methods

unsafe AllocHGlobal(i64 bytes) : void*
#

static

bytes of native memory, zeroed (FreeHGlobal gives it back).

unsafe FreeHGlobal(void* block)
#

static

unsafe AllocCoTaskMem(i32 bytes) : void*
#

static

bytes of native memory, zeroed (FreeCoTaskMem gives it back).

unsafe FreeCoTaskMem(void* block)
#

static

unsafe StringToCoTaskMemUTF8(str text) : u8*
#

static

A null-terminated UTF-8 copy of text in native memory (FreeCoTaskMem gives it back).

unsafe StringToHGlobalUTF8(str text) : u8*
#

static

A null-terminated UTF-8 copy of text in native memory (FreeHGlobal gives it back).

unsafe StringToHGlobalUni(str text) : u16*
#

static

A null-terminated UTF-16 copy of text in native memory (FreeHGlobal gives it back).

unsafe PtrToStringUTF8(u8* text) : str
#

static

The null-terminated UTF-8 text at text (null: an empty string).

unsafe PtrToStringUTF8(u8* text, i32 length) : str
#

static

The length bytes of UTF-8 at text.

unsafe PtrToStringUni(u16* text) : str
#

static

The null-terminated UTF-16 text at text (null: an empty string).

unsafe PtrToStringUni(u16* text, i32 length) : str
#

static

The length UTF-16 units at text.

unsafe ReadByte(void* at) : u8
#

static

unsafe ReadByte(void* at, i32 offset) : u8
#

static

unsafe ReadInt16(void* at) : i16
#

static

unsafe ReadInt16(void* at, i32 offset) : i16
#

static

unsafe ReadInt32(void* at) : i32
#

static

unsafe ReadInt32(void* at, i32 offset) : i32
#

static

unsafe ReadInt64(void* at) : i64
#

static

unsafe ReadInt64(void* at, i32 offset) : i64
#

static

unsafe ReadIntPtr(void* at) : void*
#

static

unsafe ReadIntPtr(void* at, i32 offset) : void*
#

static

unsafe WriteByte(void* at, u8 value)
#

static

unsafe WriteByte(void* at, i32 offset, u8 value)
#

static

unsafe WriteInt16(void* at, i16 value)
#

static

unsafe WriteInt16(void* at, i32 offset, i16 value)
#

static

unsafe WriteInt32(void* at, i32 value)
#

static

unsafe WriteInt32(void* at, i32 offset, i32 value)
#

static

unsafe WriteInt64(void* at, i64 value)
#

static

unsafe WriteInt64(void* at, i32 offset, i64 value)
#

static

unsafe WriteIntPtr(void* at, void* value)
#

static

unsafe WriteIntPtr(void* at, i32 offset, void* value)
#

static

unsafe Copy<T : [i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64], numeric>(T[] source, i32 start, void* destination, i32 length)
#

static

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)
#

static

Copies length elements from native memory at source into destination from start.

SizeOf<T>() : i32
#

static

The size of a T in bytes (as C sees it).

Inherited members (5)

Source

Marshal as Antril, decompiled from its Larva HIR.

System.Runtime.InteropServices.Marshal.ant
// 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);
	}
}
Esc