NAME
corm_handle - Corm open, close and save
- Functions for opening, closing and saving maps.
SYNOPSIS
Functions
Open a database.
Returns the value type (vtype) of a map.
Returns the key type (ktype) of a map.
Returns the fixed length of a type, or 0 if variable.
Write all file-backed maps to disk.
Close a map and free its resources.
Detailed Description
Functions for opening, closing and saving maps.
Note
Corm uses global state and is not thread-safe.
Capacity Limits: Initial capacity is mask + 1. When capacity is reached, the map automatically grows (doubles) unless CM_NOGROW is set. Growth is transparent to callers.
Memory Allocation: Malloc failures trigger CBUG() which terminates the process immediately. There is no graceful error handling for out-of-memory conditions.
Warning
File-backed maps are automatically saved at process exit. Explicit corm_save() calls are only needed for mid-execution persistence. The automatic save is triggered by a library destructor function registered during initialization.
Function Documentation
void corm_close (uint32_t hd)
Close a map and free its resources. Deletes all entries, closes associated secondary maps, and frees internal structures. All open maps are automatically closed at process exit by the library destructor, but you can call this explicitly to free resources earlier.
Parameters
hd Handle to close.
uint32_t corm_open (const char * filename, const char * database, uint32_t ktype, uint32_t vtype, uint32_t mask, uint32_t flags)
Open a database. Creates an in-memory map and registers its handle with the internal file cache, linking it to 'filename'. If a file exists, it loads the map data for the specified 'database'.
Parameters
filename Path to file or cache key. NULL โ in-memory only.
database Logical name within file. NULL โ skip file association.
ktype Built-in or registered key type.
vtype Built-in or registered value type.
mask Must be 2โฟ โ 1; table size is (mask + 1).
flags Bitwise OR of CM_AINDEX, CM_MIRROR, CM_SORTED, etc.
Returns
Map handle (hd).
Note
File Persistence: File-backed maps automatically load data from disk when opened, regardless of flags. The CM_MIRROR flag enables bidirectional lookup (creating a reverse map at handle hd + 1) which is useful for many persistence scenarios. The mirror map is automatically closed when closing the primary map.
Multiple databases can share a single file. Each database is identified by a hash of its name (XXH32). Data is saved and loaded based on this database ID.
void corm_save (void )
Write all file-backed maps to disk. Walks the internal cache, computes file sizes, and performs mmap/memcpy writes for maps associated with a file.
Note
This is automatically called at process exit. Explicit calls are only needed for mid-execution checkpointing or when you want to ensure data is persisted before continuing.
Author
Generated automatically by Doxygen for corm from the source code.