xtc_pdict(3)

---

xtc_pdict(3)

Erlang-style per-process dictionary

XTC_PDICT(3) Library Functions Manual XTC_PDICT(3)

xtc_pdict_put, xtc_pdict_put_with_dtor, xtc_pdict_get, xtc_pdict_erase, xtc_pdict_count, xtc_pdict_clearErlang-style per-process dictionary

#include <xtc.h>
#include <xtc_pdict.h>

int
xtc_pdict_put(const char *key, void *value);

int
xtc_pdict_put_with_dtor(const char *key, void *value, xtc_pdict_dtor_fn dtor);

void *
xtc_pdict_get(const char *key);

int
xtc_pdict_erase(const char *key);

int
xtc_pdict_count(void);

int
xtc_pdict_clear(void);

xtc_pdict is a per-process dictionary similar to Erlang's ‘put/get/erase’. Each xtc_proc(3) has its own private key-value store; entries are auto-cleaned when the proc exits, optionally invoking a destructor on each value.

The store lives in a side-table keyed by pid rather than embedded in the proc struct, so adding a pdict entry doesn't affect the in-struct fast path.

() binds key to value in the calling proc's dictionary. () is the same but takes a dtor callback. If dtor is non-NULL, it's invoked with the prior value (if any) when the entry is replaced or erased, and on every entry when the proc exits.

() returns the current value or NULL.

() removes the entry, invoking the dtor if registered.

() returns the number of entries in the calling proc's dictionary; () removes them all, invoking each registered dtor.

static void my_dtor(void *p) { free(p); }

/* Stash a per-request scratch buffer in the dict. */
char *buf = malloc(4096);
xtc_pdict_put("scratch", buf, my_dtor);

/* Later in the same proc... */
char *b = xtc_pdict_get("scratch");

xtc_proc(3), xtc_mctx(3), xtc(7)

Appeared in xtc 0.1.

May 28, 2026 Debian

View the mdoc source