[fpc-pascal] Sharing memory between applications
Carsten Bager
carsten at beas.dk
Wed May 21 09:54:09 CEST 2008
> 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.
More information about the fpc-pascal
mailing list