C Collections

clrucache · Section 3

ccache_declare_scoped

ccache_declare_scoped - declare an LRU cache that is destroyed at scope exit

C Collections (libccollections, -lccollections)

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

The same as ccache_declare(), plus
__attribute__((cleanup(clrucache__destroy_cleanup))) on the variable, so the
compiler destroys the cache when the variable leaves its scope. Call
ccache_init() on the variable before you use the cache.

name  Variable name for the cache handle
KeyT  Key type
ValT  Value type

The macro needs GCC or Clang, because it uses __attribute__((cleanup)).
 
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(3), ccache_construct_scoped(3)