Re: Memory !!!



Anil Kumar P - Roll No.98002 wrote:
I want to access a memory location assigned to a variable in program, in
another program ( a different process)
[..]

      This program will print the address of p.
      Now I want to access the value of p in another program.

It's best to avoid this where possible, because you get dependencies
between programs that are hard to debug.

Best is to use unidrectional IPC with a pipe; see 2.10 of the GTK+ FAQ
for a note on using fork() though.

Next best is often a shared file.

Next best is to use mmap() to share memory space.  This is harder
to program, harder to make robust, but it is the most efficient.
Never worry about efficiency until you have the easy way working!

The important thing is to keep the boundaries between programs as
strong as possible, for robustness. Unix is known for its robustness:
if one program crashes, others don't.  So keep it that way!

There is also System V shared memory and semaphores.  If you want
your program to be portable these days, avoid this and use mmap(),
but if yuo are only interested in Linux, it may be OK.  Unlike mmap,
there are a limited number of System V shared memory segments available
system-wide, and you have to be careful to manage them without leaking.
Some sysetms (BSD, Solaris) can be configuerd with, say, only 64 such
segments, and imlib will use those up pretty quickly :-)

System V semaphores can be useful but, again, may not be available;
a combination of the signal() function and either a shared file or mmap()
may work better.

Finally, you could use CORBA, and if it's a gnome program you are working
on, this facility is alerady available to you.  See the documentation on
www.gnome.org for a tutorial, I think, or ask on IRC (irg.gnome.org).

Lee

-- 
Liam Quin - Barefoot in Toronto - liam holoweb net - http://www.holoweb.net/
Ankh: irc.sorcery.net www.valinor.sorcery.net irc.gnome.org www.advogato.org
Author, Open Source XML Database Toolkit, Wiley August 2000
Co-author: The XML Specification Guide, Wiley 1999; Mastering XML, Sybex 2001




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]