some utilities of shared memory.
shmutil
implements a mutli-reader-single-writer hashtable and ring queue in shared memory.
Features of hashtable:
-
Support mutli-reader-single-writer operating hashtable concurrently, not support multi-writers operating hashtable at same time.
If you want to handle problem of multi processes writing the hashtable, please use cross-process lock(such as file-lock) utility to synchronize multiple processes.
-
Note: the key size can not be longer than 96 bytes.
If you wish to support large key longer than 96 bytes, please change
_Q_HASHARR_KEYSIZE
value inqlibc.h
. -
Support LRU elimination while shm space is full.
Features of ring queue:
-
Support single-reader-single-writer lock-free operating queue concurrently, and also provide locked version to handle multiple reader or multiple writer operating queue at same time.
-
Its a FIFO queue. If shm space is full while pushing,
shmutil
will returnkErrNotEnoughSpace
error.
Please refer to example directory for how to use it.
Some ideas are inspired from other open-source projects, thanks for MSEC, QCONF, libshmcache projects.