Import std.ffi.mem
Mem
struct
Public Struct Mem
Allocating, copying, filling, and comparing raw memory, for Unsafe code. What Alloc, AllocUninitialized, and Resize give, Free gives back, and what AllocAligned gives, FreeAligned.
Examples
Unsafe
Local a = Mem.Alloc(16)
Local b = Mem.Alloc(16)
Mem.Fill(a, 0xAB, 16)
Mem.Copy(b, a, 16)
Expect(Mem.Compare(a, b, 16) == 0)
Mem.Free(a)
Mem.Free(b)
End Unsafe-
bytesof new memory, all 0. Panics whenbytesis negative, or there isn't that much. -
@PanicsAtCaller Public Unsafe Static Method AllocUninitialized(bytes: Int64): Ptr<Void>static method #bytesof new memory, as Alloc gives, but not set to 0, so it holds whatever was there, which Unsafe code writes before it reads. Panics whenbytesis negative, or there isn't that much. -
@PanicsAtCaller Public Unsafe Static Method AllocAligned(bytes: Int64, alignment: Int64): Ptr<Void>static method #bytesof new memory, all 0, at an address that's a multiple ofalignment, a power of two, as SIMD code and some C libraries need. Only FreeAligned gives it back, and Resize doesn't take it. Panics whenbytesis negative,alignmentisn't a power of two, or there isn't that much. -
Gives back what AllocAligned gave. Null is nothing to give back.
-
@PanicsAtCaller Public Unsafe Static Method Resize(memory: Ptr<Void>, bytes: Int64): Ptr<Void>static method #What Alloc, AllocUninitialized, or Resize gave, in
bytesofmemory, which may have moved: it keeps what fits, and what it adds isn't 0. Null is new memory. Panics whenbytesis negative, or there isn't that much. -
Gives back what Alloc, AllocUninitialized, or Resize gave. Null is nothing to give back.
-
@PanicsAtCaller Public Unsafe Static Method Copy(destination: Ptr<Void>, source: Ptr<Void>, bytes: Int64)static method #Copies
bytesfromsourcetodestination, which can overlap. Panics whenbytesis negative, or when it isn't 0 and either is Null. -
@PanicsAtCaller Public Unsafe Static Method Fill(destination: Ptr<Void>, value: UInt8, bytes: Int64)static method #Sets
bytesof memory fromdestinationon tovalue. Panics whenbytesis negative, or when it isn't 0 anddestinationis Null. -
@PanicsAtCaller Public Unsafe Static Method Compare(a: Ptr<Void>, b: Ptr<Void>, bytes: Int64): Int32static method #Compares
bytesof memory atawith as many atb: 0 when they're the same, or -1 or 1 as the first byte that differs, read as a UInt8, is lower ataor atb. Panics whenbytesis negative, or when it isn't 0 and either is Null.
Report an issue with this page or with FutureBlitz on GitHub.