Skip to content

Functions Memory

Paul Squires edited this page Oct 19, 2026 · 1 revision

Home › Function Finder › Memory and pointers

Memory and pointers

The functions to allocate memory, share ownership of objects, grouped by what you want to do. The From column says what a program needs before it can call one:

  • built-in: nothing; it is always available.
  • std/memory: #import "std/memory", then using memory to call it by its bare name.

Jump to: Allocate and free memory · Read and write memory by address · Copy, fill and swap memory · Share one object between owners · Reach the object behind a SharedPtr · Refer to an object without keeping it alive

Allocate and free memory

Function What it does From
Allocate Reserves a number of bytes and returns a pointer to them, or 0; the bytes are not cleared. built-in
CAllocate Reserves memory for a number of elements, set to zero, and returns a pointer or 0. built-in
Reallocate Resizes a block, keeping its contents, and returns the new pointer, or 0 on failure. built-in
Deallocate Frees memory from Allocate, CAllocate or Reallocate; does nothing for a null pointer. built-in

Read and write memory by address

Function What it does From
Peek Returns a reference to the value at an address, as a byte or as a given type. built-in
Poke Writes a value to an address, as a byte or as a given type. built-in
SAdd Returns a pointer to the characters of a string. built-in

Copy, fill and swap memory

Function What it does From
Fb_Memcopy Copies a number of bytes between two memory areas that do not overlap. built-in
Fb_Memmove Copies a number of bytes between two memory areas, even when they overlap. built-in
fb_MemCopyClear Copies the first bytes of one area into another and sets the rest to zero. built-in
Clear Sets a number of bytes, starting at a variable, to zero or to a given value. built-in
Swap Exchanges the values of two variables. built-in

Share one object between owners

Function What it does From
SharedPtr Holds an object shared by several owners and destroys it when the last one lets go. std/memory
MakeShared Creates a default-constructed object and returns the first SharedPtr to it. std/memory
MakeSharedFrom Creates a copy of a value on the heap and returns a SharedPtr to it. std/memory
SharedPtr.UseCount Returns how many SharedPtr handles share the object. std/memory
SharedPtr.Reset Drops this handle's share and leaves it null; the last one out destroys the object. std/memory

Reach the object behind a SharedPtr

Function What it does From
SharedPtr.Ref Returns a reference to the object; raises an error if the handle is null. std/memory
SharedPtr.Get Returns the raw pointer to the object, or 0 if null, without adding an owner. std/memory
SharedPtr.IsNull Returns true if the handle owns no object. std/memory
SpCast Returns a SharedPtr to a base type that shares ownership with the derived one. std/memory

Refer to an object without keeping it alive

Function What it does From
WeakPtr Holds a link to a shared object that does not keep it alive, to break cycles. std/memory
WeakPtr.Lock Returns a SharedPtr to the object if it still exists, or a null one if not. std/memory
WeakPtr.Expired Returns true once the object has been destroyed. std/memory

See Also


Home · Function Finder · Keyword Index

Clone this wiki locally