Sharing memory between applications

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sharing memory between applications

Andreas Berger
I need to share memory between applications and wanted to know if FPC
has this implemented. Today I use the windows "CreateFileMapping"
function, but this is windows specific.

Another thing: To synchronize the shared memory I use a mutex which can
be initialized be name on each application. Can this be done with FPC
mutexes?

Regards,
Andreas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sharing memory between applications

Henry Vermaak
2008/5/20 Andreas Berger <[hidden email]>:
> I need to share memory between applications and wanted to know if FPC has
> this implemented. Today I use the windows "CreateFileMapping" function, but
> this is windows specific.
>
> Another thing: To synchronize the shared memory I use a mutex which can be
> initialized be name on each application. Can this be done with FPC mutexes?

on unix systems you can use mmap and semaphores to accomplish the same
thing.  in fpc there's simpleipc for one-way communication.

henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sharing memory between applications

Carsten Bager
In reply to this post by Andreas Berger
> I need to share memory between applications and wanted to know if FPC
> has this implemented. Today I use the windows "CreateFileMapping"
> function, but this is windows specific.




Here is a parcel of a program where I use sheared memory on Linux

Regards

Carsten


-------------------------

uses
   spstatus;

begin
  if not InitShaerdMemory('./udp2ser4') then
  begin
    WriteLn('Error at InitShaerdMemory');
    exit;
  end;
  spstatus.TcpSerData^.udp2ser2_terminate:=false;
end.




-----------------------------

Unit spstatus;

Interface

function InitShaerdMemory(filename:shortstring):boolean;

Type
  TcpSerData_typ=record
    Sio_Tcp_used:boolean;
    udp2ser2_terminate:boolean;
  end;


Var
  TcpSerData:^TcpSerData_typ;



Implementation

Uses ipc,BaseUnix;

function InitShaerdMemory(filename:shortstring):boolean;
var
  id,key:cInt;
  pc:array[0..255] of char;
Begin
  InitShaerdMemory:=false;
  fillchar(pc,256,0);
  pc:=filename;
  key:=ftok(pc,1);
  if key=-1 then
    exit;
  id:=shmget(key,sizeof(TcpSerData_typ),IPC_CREAT);
  if id=-1 then
    exit;
  TcpSerData:=shmat(id,nil,IPC_CREAT);
  if LongInt(TcpSerData)=-1 then
    exit;
  InitShaerdMemory:=true;
end;

End.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Sharing memory between applications

Andreas Berger
Thanks Carsten,

I didn't understand it all since I am weak in Linux. But I'll study it
and try to make a function that works for windows and linux.

Carsten Bager wrote:

>> I need to share memory between applications and wanted to know if FPC
>> has this implemented. Today I use the windows "CreateFileMapping"
>> function, but this is windows specific.
>>    
>
>
>
>
> Here is a parcel of a program where I use sheared memory on Linux
>
> Regards
>
> Carsten
>
>
> -------------------------
>
> uses
>    spstatus;
>
> begin
>   if not InitShaerdMemory('./udp2ser4') then
>   begin
>     WriteLn('Error at InitShaerdMemory');
>     exit;
>   end;
>   spstatus.TcpSerData^.udp2ser2_terminate:=false;
> end.
>
>
>
>
> -----------------------------
>
> Unit spstatus;
>
> Interface
>
> function InitShaerdMemory(filename:shortstring):boolean;
>
> Type
>   TcpSerData_typ=record
>     Sio_Tcp_used:boolean;
>     udp2ser2_terminate:boolean;
>   end;
>
>
> Var
>   TcpSerData:^TcpSerData_typ;
>
>
>
> Implementation
>
> Uses ipc,BaseUnix;
>
> function InitShaerdMemory(filename:shortstring):boolean;
> var
>   id,key:cInt;
>   pc:array[0..255] of char;
> Begin
>   InitShaerdMemory:=false;
>   fillchar(pc,256,0);
>   pc:=filename;
>   key:=ftok(pc,1);
>   if key=-1 then
>     exit;
>   id:=shmget(key,sizeof(TcpSerData_typ),IPC_CREAT);
>   if id=-1 then
>     exit;
>   TcpSerData:=shmat(id,nil,IPC_CREAT);
>   if LongInt(TcpSerData)=-1 then
>     exit;
>   InitShaerdMemory:=true;
> end;
>
> End.
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 8.0.100 / Virus Database: 269.24.1/1466 - Release Date: 5/25/2008 6:49 PM
>  
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal