C Collections

clrucache · Section 3

ccache_declare

ccache_declare - declare an uninitialised LRU cache variable with type tracking

C Collections (libccollections, -lccollections)

#include <ccollections/clrucache.h>
 
ccache_declare(name, KeyT, ValT);

Declares the ccache handle variable name, together with two hidden
companion type variables that carry the KeyT and ValT type information
into the later ccache_init(), ccache_get() and ccache_set() calls.
 
Call ccache_init() on the variable before you use the cache.

name  Variable name for the cache handle
KeyT  Key type (for example int, char *, struct MyKey)
ValT  Value type (for example double, struct MyVal)

An array key type or value type, such as int[2] or char[16], is a
compile error, and the message says to wrap the array in a struct. The
macros copy a key or a value by assignment, C cannot assign an array,
and without the error the cache would store the address of the
caller's array instead of its elements. A struct that holds the
array works.

ccache_declare(cache, int, double);
ccache_init(cache, 128, NULL, NULL, NULL);
/* ... use cache ... */
ccache_destroy(cache);

ccache_declare_scoped(3), ccache_init(3), ccache_construct(3)