Bond 0.9
Bond Standard Library API Documentation
Loading...
Searching...
No Matches
memory.bond

API for scope-based and manual dynamic memory management, as well as other memory related functions. More...

Classes

struct  Bond::Collector
 An opaque set of collected allocations that are freed together. More...

Functions

Collector * Bond::GetCollector ()
 Returns the Collector of the calling function.
void * Bond::Allocate (ulong size)
 Allocates a block of memory that must be freed manually.
void * Bond::AllocateCollected (ulong size)
 Allocates a block of memory that is freed automatically when the calling function returns.
void * Bond::AllocateWithCollector (Collector *collector, ulong size)
 Allocates a block of memory that is freed automatically along with a given Collector.
void * Bond::AllocateAligned (ulong size, uint alignment)
 Allocates an aligned block of memory that must be freed manually.
void * Bond::AllocateAlignedCollected (ulong size, uint alignment)
 Allocates an aligned block of memory that is freed automatically when the calling function returns.
void * Bond::AllocateAlignedWithCollector (Collector *collector, ulong size, uint alignment)
 Allocates an aligned block of memory that is freed automatically along with a given Collector.
void Bond::Free (void *ptr)
 Frees a block of memory allocated with Allocate.
void Bond::FreeAligned (void *ptr)
 Frees a block of memory allocated with AllocateAligned.
void Bond::Memcpy (void *dest, void *src, ulong size)
 Copies bytes from one block of memory to another. The blocks must not overlap.

Detailed Description

API for scope-based and manual dynamic memory management, as well as other memory related functions.

include "memory.bond";

Function Documentation

◆ Allocate()

void * Bond::Allocate ( ulong size)

Allocates a block of memory that must be freed manually.

Parameters
sizeThe size of the block in bytes.
Returns
A pointer to the allocated memory, which must be freed with Free.

◆ AllocateAligned()

void * Bond::AllocateAligned ( ulong size,
uint alignment )

Allocates an aligned block of memory that must be freed manually.

Parameters
sizeThe size of the block in bytes.
alignmentThe alignment of the block in bytes.
Returns
A pointer to the allocated memory, which must be freed with FreeAligned.

◆ AllocateAlignedCollected()

void * Bond::AllocateAlignedCollected ( ulong size,
uint alignment )

Allocates an aligned block of memory that is freed automatically when the calling function returns.

Parameters
sizeThe size of the block in bytes.
alignmentThe alignment of the block in bytes.
Returns
A pointer to the allocated memory, which must not be freed manually.

◆ AllocateAlignedWithCollector()

void * Bond::AllocateAlignedWithCollector ( Collector * collector,
ulong size,
uint alignment )

Allocates an aligned block of memory that is freed automatically along with a given Collector.

Parameters
collectorThe Collector with which the memory is registered. If null, the Collector of the calling function is used.
sizeThe size of the block in bytes.
alignmentThe alignment of the block in bytes.
Returns
A pointer to the allocated memory, which must not be freed manually.

◆ AllocateCollected()

void * Bond::AllocateCollected ( ulong size)

Allocates a block of memory that is freed automatically when the calling function returns.

Parameters
sizeThe size of the block in bytes.
Returns
A pointer to the allocated memory, which must not be freed manually.

◆ AllocateWithCollector()

void * Bond::AllocateWithCollector ( Collector * collector,
ulong size )

Allocates a block of memory that is freed automatically along with a given Collector.

Parameters
collectorThe Collector with which the memory is registered. If null, the Collector of the calling function is used.
sizeThe size of the block in bytes.
Returns
A pointer to the allocated memory, which must not be freed manually.

◆ Free()

void Bond::Free ( void * ptr)

Frees a block of memory allocated with Allocate.

Parameters
ptrA pointer returned by Allocate.

◆ FreeAligned()

void Bond::FreeAligned ( void * ptr)

Frees a block of memory allocated with AllocateAligned.

Parameters
ptrA pointer returned by AllocateAligned.

◆ GetCollector()

Collector * Bond::GetCollector ( )

Returns the Collector of the calling function.

Allocations registered with it are freed when the calling function returns. The returned pointer can be passed to a function that it calls, so that the callee can allocate memory that outlives it.

◆ Memcpy()

void Bond::Memcpy ( void * dest,
void * src,
ulong size )

Copies bytes from one block of memory to another. The blocks must not overlap.

Parameters
destA pointer to the memory into which the bytes are copied.
srcA pointer to the memory from which the bytes are copied.
sizeThe number of bytes to copy. Both pointers must be non-null unless it is 0.