Hi All,
This is my first post - and I am just beginning C so your help is greatly appreciated.
I'm trying to understand the size_t param for shmget() as well as the limits of shared memory in general. I'm on Linux for now, but want this to be cross platform.
When creating a shared memory segment I create the size based on filesize (character length) + a buffer + 1 (for an extra \0 since for now I am storing strings).
When I later go to read a shared memory segment I am confused as to what is happening. I have a ton of questions so I hope I am asking them correctly.
shmget(key,filesize, IPC_CREAT | 0555)
If I am retrieving a shared memory segment how would I know filesize ahead of time? Would I need to?
When I get the stat from shmctrl it is a different size than PAGE_SIZE (which I thought it rounded up to) and from the size I allocated. So what is size of shared memory segment really about?
I've ready quite a bit on the web and some of the Linux man page. But I don't understand the size allocations and limitations of shared memory segments.
PS
Should I remove IPC_CREAT if I want it to fail if it doesn't exist?
What I am trying to do is persist memory (some strings, and preferably a struct). The application doesn't run as a dameon - the applications life span is short, so I don't believe I have persistant memory. Reading from disk and DB is slower than I want.
I suppose there are a lot of OS specific issues with shmget since it is os dependent.
If there is a way to persist memory in malloc() I guess that would suffice. If the application had it's own protected memory where I could use actual memory addresses would that work instead of shmget()?