xtc_pdict(3)
---xtc_pdict(3)
Erlang-style per-process dictionary
| XTC_PDICT(3) | Library Functions Manual | XTC_PDICT(3) |
NAME
xtc_pdict_put,
xtc_pdict_put_with_dtor,
xtc_pdict_get,
xtc_pdict_erase,
xtc_pdict_count,
xtc_pdict_clear —
Erlang-style per-process dictionary
SYNOPSIS
#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);
DESCRIPTION
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.
xtc_pdict_put()
binds key to value in the
calling proc's dictionary.
xtc_pdict_put_with_dtor()
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.
xtc_pdict_get()
returns the current value or NULL.
xtc_pdict_erase()
removes the entry, invoking the dtor if registered.
xtc_pdict_count()
returns the number of entries in the calling proc's dictionary;
xtc_pdict_clear()
removes them all, invoking each registered dtor.
EXAMPLES
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");
SEE ALSO
HISTORY
Appeared in xtc 0.1.
| May 28, 2026 | Debian |