🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9805

Re: Same memory piece for 2 running applications?

#9805
From: Remy Lebeau (TeamB)
Date: Tue, 08 Jun 2004 17:41
37 lines
2262 bytes
"Ramy" <Ramy@NoMail.com> wrote in message
news:40c58d7a$1@newsgroups.borland.com...

> I need to write 2 applications which runs at the same time
> on the computer (Windows-2000) and share same piece
> of memory for exchanging data between each other

Use a named file mapping to share a block of memory between the two
programs.  Look at CreateFileMapping() and MapViewOfFile().  When both
applications call CreateFileMapping() using the same name, they will get a
handle to the same global mapping object.  Then MapViewOfFile() can turn
that object into a pointer that both applications can then use to access the
shared memory.

> if for example one application change this matrix, the anther
> application can take the matrix from the memory and use it,
> or display it for example...

Just make sure that you provide adequate synchronization, such as via a
named mutex.

> Can i allocate an array like this -
>
> float array[500][400];
>
> then write it's address ( &array[0][0] ) and size
> (500x400) in a file, so the other application can read the
> file and access the array by using the pointer and the size
> from this file?

No.  Applications have their own address spaces.  They cannot access each
other's memory directly.  The value of a pointer in one application may not
be a meaningful value in another program.


Gambit
Technical Details
Message-ID: <40c5fb45$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40c58d7a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,1b6c238d7724ed66
X-Google-Attributes: gid10cc67,public
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40c58d7a$1@newsgroups.borland.com>
Subject: Re: Same memory piece for 2 running applications? 
Date: Tue, 8 Jun 2004 10:41:33 -0700
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.169.168.124
Message-ID: <40c5fb45$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1086716741 68.169.168.124 (8 Jun 2004 10:45:41 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail