struct shared_memory_t { int value1; int value2; char* buffer; }; shmid = shmget(key, sizeof(shared_memory_t) + segsize, 0666|IPC_CREAT); shared_memory_t* mem = (shared_memory_t*) shmat(*shmid, NULL, 0); So I was trying to map the shared memory to a custom structure. Now I do not know how large the segsize is until user starts program and inputs a value. I wanted buffer to be pointer to beginning of the memory space after the int values. Now if I do this I get memory faults. I can attach it and get the starting memory space with:
void* mem = shmat(shmid, NULL, 0); Any hints on how I can get it in a state where I can do mem->value1 and access the data buffer for raw data bytes?
sizeneeds to be a multiple of a memory page size? Probably a multiple of 4096.shmget, don't assume that it will just work.sizedoes not have to be a multiple of the page size; the system will automatically round it up.