static class · System.Runtime.InteropServices

NativeMemory

public static class NativeMemory

Native memory blocks (not seen by the collector).

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

Inheritance

Base classes
Any NativeMemory

Methods

unsafe Alloc(u64 bytes) : void*
#

static

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

unsafe AllocZeroed(u64 count, u64 size) : void*
#

static

count elements of size bytes, zeroed.

unsafe Free(void* block)
#

static

unsafe Copy(void* source, void* destination, u64 bytes)
#

static

Copies bytes bytes from source to destination (the blocks do not overlap).

unsafe Fill(void* block, u64 bytes, u8 value)
#

static

Sets bytes bytes at block to value.

unsafe Clear(void* block, u64 bytes)
#

static

Inherited members (5)

Source

NativeMemory as Antril, decompiled from its Larva HIR.

System.Runtime.InteropServices.NativeMemory.ant
// System.Runtime.InteropServices.NativeMemory — System.Core (decompiled from Larva HIR)

into namespace System.Runtime.InteropServices
{
	/// Native memory blocks (not seen by the collector).
	public static class NativeMemory
	{
		public:
			/// `bytes` of native memory, zeroed (Free gives it back).
			unsafe Alloc(u64 bytes) : void* => (void*)CStrings.Allocate((i64)bytes);

			/// `count` elements of `size` bytes, zeroed.
			unsafe AllocZeroed(u64 count, u64 size) : void* => (void*)CStrings.Allocate((i64)(count * size));

			unsafe Free(void* block)
			{
				CStrings.Release((u8*)block);
			}

			/// Copies `bytes` bytes from `source` to `destination` (the blocks do not overlap).
			unsafe Copy(void* source, void* destination, u64 bytes)
			{
				u8* from = (u8*)source;
				u8* to = (u8*)destination;
				loop (u64 i = 0; i < bytes; i++)
					*(to + (i64)i) = *(from + (i64)i);
			}

			/// Sets `bytes` bytes at `block` to `value`.
			unsafe Fill(void* block, u64 bytes, u8 value)
			{
				u8* at = (u8*)block;
				loop (u64 i = 0; i < bytes; i++)
					*(at + (i64)i) = value;
			}

			unsafe Clear(void* block, u64 bytes)
			{
				Fill(block, bytes, 0);
			}
	}
}
Esc