Shared Memory - shmget questions

This is a discussion on Shared Memory - shmget questions within the C Programming forums, part of the General Programming Boards category; Hi All, This is my first post - and I am just beginning C so your help is greatly appreciated. ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    1

    Shared Memory - shmget questions

    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()?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > and I am just beginning C
    This is a huge task for someone who is just beginning C.

    Could you elaborate on the problem you're trying to solve?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with insert/delete binary search tree
    By Nazgulled in forum C Programming
    Replies: 39
    Last Post: 03-25-2009, 04:24 PM
  2. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  3. Shared memory implementation using thread
    By kumars in forum C Programming
    Replies: 5
    Last Post: 06-18-2008, 04:24 AM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21