microlisp 0.1.0
A small Scheme-subset interpreter in modern C.
Loading...
Searching...
No Matches
Data Fields
microlisp_allocator Struct Reference

Caller-supplied allocator. More...

#include <microlisp.h>

Data Fields

void *(* alloc )(size_t size, void *user)
 Allocate size bytes.
 
void(* free )(void *ptr, void *user)
 Free a pointer previously returned by alloc.
 
void * user
 Opaque user data passed verbatim to alloc and free.
 

Detailed Description

Caller-supplied allocator.

Pass NULL to microlisp_state_create to use the platform malloc / free.

The implementation only calls alloc and free; it does not call realloc, calloc, or memalign.

Thread safety: the caller's alloc / free functions must
themselves be MT-Safe if the microlisp_allocator is shared across threads (i.e. used to construct multiple states that run concurrently).

Field Documentation

◆ alloc

void *(* microlisp_allocator::alloc) (size_t size, void *user)

Allocate size bytes.

Returns NULL on failure. Must be non-NULL whenever the surrounding microlisp_allocator struct is non-NULL.

Alignment contract: every returned non-NULL pointer must be aligned to at least 8 bytes (alignof(uint64_t)). The interpreter's value representation reserves the low 3 bits of heap-object pointers for a type tag; allocators that return weaker alignment (1- or 4-byte) will silently corrupt values on the first GC cycle. Platform malloc always meets this on any supported target; custom arenas must round up explicitly.

◆ free

void(* microlisp_allocator::free) (void *ptr, void *user)

Free a pointer previously returned by alloc.

Must be non-NULL whenever the surrounding microlisp_allocator struct is non-NULL. free(NULL) is a no-op.

◆ user

void* microlisp_allocator::user

Opaque user data passed verbatim to alloc and free.


The documentation for this struct was generated from the following file: