[fpc-pascal] Sharing memory between applications

Andreas Berger Andreas at TheBergerClan.org
Mon May 26 15:02:52 CEST 2008


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  -  fpc-pascal at lists.freepascal.org
> 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
>   



More information about the fpc-pascal mailing list