Thread: Shared "Integers"

  1. #1
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68

    Shared "Integers"

    How can you share integer values. With the functions given in C, it is only possible to allocate a flat memory space.

    if you have a shared memory area that with the starting address at INTEGER,

    Then this would give a runtime error

    *INTEGER=1;
    Is there a direct way of sharing an integer ?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Share how? Between functions? Between modules? Between programs?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    Sorry..should have been more specific.......share amoung processes..............

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    this is compiler specific, in linux there are many ways including mapped memory and shared memory. Might want to look at shmget() and mmap().
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  5. #5
    char main() RoshanX's Avatar
    Join Date
    Mar 2003
    Posts
    68
    I finally got the program working with MMAP().
    Question :
    I am not that clear about the working os MMAP. Does the shared memeory reside in a file . ?

  6. #6
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    from what I understand, it makes a file and makes it point to memory or something of that effect, then the other programs can read that memory.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  7. #7
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by RoshanX
    I finally got the program working with MMAP().
    Question :
    I am not that clear about the working os MMAP. Does the shared memeory reside in a file . ?
    Did you try google on "mmap() function"?

    One of many hits:
    http://www.opengroup.org/onlinepubs/...ions/mmap.html
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  3. Writing input from a file into shared memory
    By RazielX in forum C Programming
    Replies: 2
    Last Post: 09-23-2004, 12:34 PM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM
  5. XP Shared Drive Problem(?)
    By Davros in forum Tech Board
    Replies: 2
    Last Post: 10-06-2002, 01:37 PM