« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

$

#define $(T, ...)
#define $I(X)
#define $F(X)
#define $S(X)
#define $R(X)
#define $B(X)

Allocate memory for the given type T on the stack and copy in the given arguments ... as struct members. Shorthand constructors exist for native types:

  • $I -> Int $F -> Float $S -> String
  • $R -> Ref $B -> Box

alloc

#define alloc_stack(T)
var alloc(var type);
var alloc_raw(var type);
var alloc_root(var type);

Allocate memory for a given type. To avoid the Garbage Collector completely use alloc_raw, to register the allocation as a root use alloc_root. In the case of raw or root allocations the corresponding dealloc function should be used when done. Memory allocated with alloc_stack is not managed by the Garbage Collector.

dealloc

void dealloc(var self);
void dealloc_raw(var self);
void dealloc_root(var self);

Deallocate memory for object self manually. If registered with the Garbage Collector then entry will be removed. If the raw variation is used memory will be deallocated without going via the Garbage Collector.

Examples

Usage

/* Allocation deallocated by Garbage Collector */
var x = alloc(Int);
construct(x, $I(10));

Avoid Garbage Collection

/* Allocation must be manually deallocated */
var x = alloc_raw(Int);
construct(x, $I(10));
destruct(x);
dealloc_raw(x);

Alloc


Memory Allocation

The Alloc class can be used to override how memory is allocated for a given data type. By default memory is allocated using calloc along with the Size class to determine the amount of memory to allocate.

A custom allocator should be careful to also initialise the header for the allocated memory using the function header_init. Cello objects without a header wont be recognised as such as so will throw errors when used with Cello functions.

Allocated memory is automatically registered with the garbage collector unless the functions alloc_raw and dealloc_raw are used.

Definition

struct Alloc {
  var (*alloc)(void);
  void (*dealloc)(var);
};

Derivers

  • Array |     Sequential Container
  • Box |     Unique Pointer
  • Exception |     Exception Object
  • File |     Operating System File
  • Filter |     Filtered Iterable
  • Float |     Floating Point Object
  • Function |     Function Object
  • GC |     Garbage Collector
  • Int |     Integer Object
  • List |     Linked List
  • Map |     Apply Function to Iterable
  • Mutex |     Mutual Exclusion Lock
  • Process |     Operating System Process
  • Range |     Integer Sequence
  • Ref |     Shared Pointer
  • Slice |     Partial Iterable
  • String |     String Object
  • Table |     Hash table
  • Thread |     Concurrent Execution
  • Tree |     Balanced Binary Tree
  • Tuple |     Basic Collection
  • Zip |     Multiple Iterator

Implementers

  • Type |     Metadata Object

Back