Thread: Sharing memory

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    7

    Red face Sharing memory

    I want to have a code which can share memory to a paticular variable while forking.

    i know that shmget() helps in sahring memory but not clear how to use it.


    Could u please help

  2. #2
    piece of advise
    Guest
    > i know that shmget() helps in sahring memory but not clear how to use it

    calling shmget() will give you what is called an shmid (an int). You will either create the shared memory, or will just get the shmid of an already existing shared memory already (watch carefully the options you pass to the function)

    With this shmid you can attach to a memory segment by calling shmat().

    shmat() will return a pointer to your memory segment.

    You need these two basic steps. Then you can do whatever you want with it. Clean when you're done.

    shmdt() will detach the shared memory segment

    shmctl() with IPC_RMID will delete the segment.

    Read the documentation of the functions for detail on the options.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  2. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  3. Sharing Memory among Processes
    By doom in forum C# Programming
    Replies: 4
    Last Post: 10-04-2005, 06:51 PM
  4. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  5. What's the best memory (RAM) type?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 12-15-2001, 12:37 AM