Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-05

Sharing memory between applications

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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

Reply by email

Henry Vermaak
to Andreas Berger

2008/5/20 Andreas Berger :

Show quoted text 6 lines
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

Reply by email

Carsten Bager
to Andreas Berger: I need to share memory between applications and wanted to know if FPC has this…
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.

Reply by email

Andreas Berger
to Carsten Bager

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 88 lines
> 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 - 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

Reply by email