diff --git a/src/SharedMemoryAccess.cpp b/src/SharedMemoryAccess.cpp index 456e47b..7e12c69 100644 --- a/src/SharedMemoryAccess.cpp +++ b/src/SharedMemoryAccess.cpp @@ -63,23 +63,25 @@ void writeSharedMemory(char *data, int size, int offset) { } char *getSharedMemory() { - constexpr bool useLocal = false; + bool useLocal = false; - if(useLocal){ + 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 if (localSharedMemory.empty()) { initSemaphore(); 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); - } } }