Skip to main content

Memory Class

NuGet: GHIElectronics.TinyCLR.Native
Assembly: GHIElectronics.TinyCLR.Native
Namespace: GHIElectronics.TinyCLR.Native

Allocator façade exposing both the managed (GC) heap and the unmanaged heap. Most apps don't touch this directly — use UnmanagedBuffer when you need a fixed-address byte buffer (for DMA, native interop, etc.).

public class Memory

Properties​

ManagedMemory​

public static Memory ManagedMemory { get; }

The managed (GC) heap allocator.

UnmanagedMemory​

public static Memory UnmanagedMemory { get; }

The unmanaged heap allocator (fixed addresses, not GC-tracked).

UsedBytes​

public long UsedBytes { get; }

Bytes currently allocated from this heap.

FreeBytes​

public long FreeBytes { get; }

Bytes currently free in this heap.

Methods​

Allocate(long length)​

public IntPtr Allocate(long length)

Allocates length bytes; returns the pointer.

Returns IntPtr

Allocate(IntPtr length)​

public extern IntPtr Allocate(IntPtr length)

Allocates the given number of bytes.

Returns IntPtr

Free(IntPtr ptr)​

public extern void Free(IntPtr ptr)

Frees a pointer returned by Allocate(long).

ToBytes(IntPtr ptr, long length)​

public byte[] ToBytes(IntPtr ptr, long length)

Returns a byte[] aliased to a fixed-address region (no copy).

Returns byte[]

ToBytes(IntPtr ptr, IntPtr length)​

public extern byte[] ToBytes(IntPtr ptr, IntPtr length)

Returns a byte[] aliased to a fixed-address region (no copy).

Returns byte[]

GetStats(out IntPtr used, out IntPtr free)​

public extern void GetStats(out IntPtr used, out IntPtr free)

Reads current heap usage and free space.

ExtendHeap()​

public static extern void ExtendHeap()

Permanently extends the managed heap into external SDRAM (where supported).

IsExtendedHeap()​

public static extern bool IsExtendedHeap()

True when the managed heap has been extended via ExtendHeap.

Returns bool