Shared-memory APIs.
More...
Go to the source code of this file.
|
int | qshm_init (const char *keyfile, int keyid, size_t size, bool recreate) |
| Initialize shared-memory.
|
|
int | qshm_getid (const char *keyfile, int keyid) |
| Get shared memory identifier by keyfile and keyid for existing shared memory.
|
|
void * | qshm_get (int shmid) |
| Get a pointer of shared memory.
|
|
bool | qshm_free (int shmid) |
| De-allocate shared memory.
|
|
Shared-memory APIs.
- Note
[your header file]
struct SharedData {
(... structrue definitions ...)
}
[shared memory creater]
int shmid =
qshm_init(
"/some/file/for/generating/unique/key",
's',
sizeof(
struct SharedData),
true);
if(shmid < 0) {
printf("ERROR: Can't initialize shared memory.\n");
return -1;
}
struct SharedData *sdata = (SharedData *)
qshm_get(shmid);
if(sdata == NULL) {
printf("ERROR: Can't get shared memory.\n");
return -1;
}
[shared memory user]
int shmid =
qshm_getid(
"/some/file/for/generating/unique/key",
's');
if(shmid < 0) {
printf("ERROR: Can't get shared memory id.\n");
return -1;
}
struct SharedData *sdata = (SharedData *)
qshm_get(shmid);
if(sdata == NULL) {
printf("ERROR: Can't get shared memory.\n");
return -1;
}
void * qshm_get(int shmid)
Get a pointer of shared memory.
int qshm_init(const char *keyfile, int keyid, size_t size, bool recreate)
Initialize shared-memory.
int qshm_getid(const char *keyfile, int keyid)
Get shared memory identifier by keyfile and keyid for existing shared memory.
Definition in file qshm.c.
◆ qshm_init()
int qshm_init |
( |
const char * |
keyfile, |
|
|
int |
keyid, |
|
|
size_t |
size, |
|
|
bool |
recreate |
|
) |
| |
Initialize shared-memory.
- Parameters
-
keyfile | seed for generating unique IPC key |
keyid | seed for generating unique IPC key |
size | size of shared memory |
recreate | set to true to re-create shared-memory if already exists |
- Returns
- non-negative shared memory identifier if successful, otherwise returns -1
Definition at line 91 of file qshm.c.
◆ qshm_getid()
int qshm_getid |
( |
const char * |
keyfile, |
|
|
int |
keyid |
|
) |
| |
Get shared memory identifier by keyfile and keyid for existing shared memory.
- Parameters
-
keyfile | seed for generating unique IPC key |
keyid | seed for generating unique IPC key |
- Returns
- non-negative shared memory identifier if successful, otherwise returns -1
Definition at line 127 of file qshm.c.
◆ qshm_get()
void * qshm_get |
( |
int |
shmid | ) |
|
Get a pointer of shared memory.
- Parameters
-
shmid | shared memory identifier |
- Returns
- a pointer of shared memory
Definition at line 149 of file qshm.c.
◆ qshm_free()
bool qshm_free |
( |
int |
shmid | ) |
|
De-allocate shared memory.
- Parameters
-
shmid | shared memory identifier |
- Returns
- true if successful, otherwise returns false
Definition at line 167 of file qshm.c.