~ use local memory if no shared memory exists
This commit is contained in:
parent
7b2ddf9e0a
commit
5aa0a7862f
@ -63,7 +63,17 @@ void writeSharedMemory(char *data, int size, int offset) {
|
||||
}
|
||||
|
||||
char *getSharedMemory() {
|
||||
constexpr bool useLocal = false;
|
||||
bool useLocal = false;
|
||||
|
||||
if(!useLocal){
|
||||
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
|
||||
if(shmId < 0) {
|
||||
//no shared memory found
|
||||
useLocal = true;
|
||||
} else {
|
||||
return (char *) shmat(shmId, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(useLocal) {
|
||||
//using a local buffer for shared memory testing
|
||||
@ -72,14 +82,6 @@ char *getSharedMemory() {
|
||||
localSharedMemory.resize(impl.sharedMemorySize * 1024);
|
||||
}
|
||||
return &localSharedMemory[0];
|
||||
}else {
|
||||
int shmId = shmget(impl.sharedMemoryKey, NULL, 0);
|
||||
if(shmId < 0) {
|
||||
// we could return -1, not sure if it will be useful to continue after there is no shm allocated for any reason
|
||||
return nullptr;
|
||||
} else {
|
||||
return (char *) shmat(shmId, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user