Thread: Any of you Worked with Shared Memory in Linux?

  1. #1
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531

    Any of you Worked with Shared Memory in Linux?

    I was wandering if any of you worked with Shared Memory in Linux except Govtcheez .
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I have a little shared memory stuff at hand, although it was written by others, I only maintain it. Its not on Linux either... so not much help, eh?!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531

    Question

    Seems interesting.. So you did it in Windows

    You can share your technique here with if not a problem of copy rights.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    I can help with shared memory... what exactly are you looking to know?

    starX
    www.axisoftime.com

  5. #5
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    I want to work with a data structure like BTree.

    Here I'm going to the specific point. I got problem when I have to know the size of the memory I need before I allocate as shared. But I need such a technique where I don't have to know the size of memory and I can dynametically increase or decrease the size of memory I need to share.

    Let know if it's not much clear.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    Just so I know I'm following you, you need to know how much memory you will need initially, but then you want the ability to change it to unspecified amounts during runtime?

    starX
    www.axisoftime.com

  7. #7
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    Yeah.. you are correct.

    Code:
    #define SHM_BLOCK_ID  100   // whatever
    #define SHM_SIZE    (20*1024*1024)
    #define PERMISSIONS 0666 
    
    key = ftok( ".", SHM_BLOCK_ID)
    What about if I store the next SHM_BLOCK_ID at the end of the first SHMD_BLOCK ?
    Last edited by zahid; 01-31-2003 at 10:56 PM.
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    I must admit I've had to go back and do some reading for this one. If you post your code I'll have a better idea as to what functions you're playing with, but for now my advice would have to be to keep your shared mem size a variable. That way you can create one shared mem block, and when you need to expand its size you can create a new one (using the new size), and basically copy the data from the old block to the new one. Just remember to free up the old block when you're done with it.

    I would, however, strongly recommend against using ftok(), try casting the key as a key_t type in your shmget call instead, i.e.:

    Code:
    shmget((key_t)3647, sizeof(struct your_custom_header), 0666 | IPC_CREAT);
    Hope this helps somewhat.

    starX
    www.axisoftime.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shared memory problem
    By sangfroid in forum C Programming
    Replies: 5
    Last Post: 03-25-2007, 01:29 PM
  2. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  3. Shared memory woes
    By joshdick in forum C Programming
    Replies: 4
    Last Post: 07-28-2005, 08:59 AM
  4. shared memory can not read value over 255
    By jbsloan in forum C Programming
    Replies: 4
    Last Post: 04-03-2005, 11:56 AM
  5. Shared memory in Linux: B-TREE of structures
    By zahid in forum Linux Programming
    Replies: 3
    Last Post: 01-26-2002, 11:15 PM