🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Same memory piece for 2 running applications?

#10817
From: Steve Aletto
Date: Wed, 17 Mar 2004 09:10
38 lines
2280 bytes
"Ramy" <Ramy@none.org> ha scritto nel messaggio
news:40580ba8$1@newsgroups.borland.com...
>
> Such as?
Such as mutexes, semaphores, etc. There's a complete chapter about
'Synchronization' in MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/synchronization.asp

> Can i for example 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?

Sure you can. And if I recall correctly, CreateFileMapping can be used
to allocate and use directly _memory_ instead of files (using
(HANDLE)0xFFFFFFFF as first parameter). My suggestion is to use a
struct (let's call it StructSharedData) with all the data you need:

struct StructSharedData
    {
    int whatever;
    } *SD;

HANDLE hSD;
hSD = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0,
sizeof(*SD), "SD");
SD = (StructSharedData *)MapViewOfFile(hSD, FILE_MAP_WRITE, 0, 0,
sizeof(*SD));
...
Use SD as needed...
...
UnmapViewOfFile(SD);
CloseHandle(hSD);

Steve.
Technical Details
Message-ID: <40581645$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4057f989$1@newsgroups.borland.com> <405803a6@newsgroups.borland.com> <40580a64$1@newsgroups.borland.com> <40580ba8$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e8102036f7e0120d
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-03-17 01:39:47 PST
Reply-To: "Steve Aletto" <steve_alettoANTI@SPAMhotmail.com>
From: "Steve Aletto" <steve_alettoANTI@SPAMhotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4057f989$1@newsgroups.borland.com> <405803a6@newsgroups.borland.com> <40580a64$1@newsgroups.borland.com> <40580ba8$1@newsgroups.borland.com>
Subject: Re: Same memory piece for 2 running applications?
Date: Wed, 17 Mar 2004 10:10:08 +0100
Lines: 40
Organization: Steve Aletto
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 80.105.101.132
Message-ID: <40581645$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079514693 80.105.101.132 (17 Mar 2004 01:11:33 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail