1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Program for shared memory in c++

Discussion in 'C++' started by bashamsc, Jan 25, 2008.

  1. shabbir

    shabbir Administrator Staff Member

    Even I did the same and so we would like to make sure we conclude that its an original contribution.
     
  2. bashamsc

    bashamsc New Member

    See to understand the program first u need to have an idea of shared memory.

    Shared memory comes under Inter-Process Communication.

    Shared memory is the fastest of all IPC.

    Shared memory comes under System V IPC.

    SHARED MEMORY:

    Shared memory is one of the three System V IPC.

    It allows two unrelated processes to access the same logical memory.

    Shared memory is a very efficient way of transferring data between two running processes.


    In the program i have used these functions.

    shmget and shmat for shared memory.

    shmget is used to create shared memory.

    shmat is used to attach the shared memory to the address space of the process.

    When we come to the program,i have created two process i.e process-1 and process-2.

    process-1 and process-2 uses same memory i.e shared memory.

    I have created a single bit shared memory to control the two process not to access the shared memory at a time.

    When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .

    Run the two process at a time (i.e in two terminals ) and u will observe that When process-1 uses the shared memory then process-2 waits until process-1 completes its work and wise versa .
     
    Last edited: Feb 26, 2008
  3. imrantechi

    imrantechi New Member

    Okay!!! Thanks man...
     
  4. debleena_doll2002

    debleena_doll2002 New Member

    Leave it bashamsc !!! your effort is really apprecited. Now please dont make issue more. That article should be nominated!!! Finallllll
     
  5. shabbir

    shabbir Administrator Staff Member

  6. lead.smart34

    lead.smart34 New Member

    its complex
     
  7. crazytolearn57

    crazytolearn57 New Member

    what is this problem of copy
     
  8. rlearntowin1

    rlearntowin1 New Member

  9. bashamsc

    bashamsc New Member

  10. shabbir

    shabbir Administrator Staff Member

  11. asadullah.ansari

    asadullah.ansari TechCake

    Congrates man!!!
     
  12. aisha.ansari84

    aisha.ansari84 New Member

    congrats you won
     
  13. sorabh284

    sorabh284 New Member

    when we pass object as argument to a function, then whether constructor or destructor are called or not.
     
  14. Mufasa

    Mufasa New Member

    Hi @all,

    ok this thread is a bit old already.... but I'm working on quite the same issue now so I thought I refresh this instead of starting a new...

    1st: Big thanks to bashamsc for this great code!!

    Now what I am trying to do for a while now.... ( without any success until now :( ) is to access this SHM with PHP. So I have a shared-memory created with C++ and I want to read and change the data inside with PHP and read with C++ again and so on...... U know what I mean? I know a bit difficult to explain....

    Allright, I know how to create a shm with php and write data inside..... but how the h*** can I access this C++ created shm??

    Appreciate every help or suggestion.

    Thanks in advance & regards from Germany :)
     
  15. banty_raju123

    banty_raju123 New Member

    ur information is very useful for me thankx
     

Share This Page