Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory Mapping

Status
Not open for further replies.

csbrmg

Programmer
Joined
Jul 1, 2003
Messages
9
Location
ZA
The major problem that i have with file mapping is that once the filemapping ad the map view is created how would a create an instance of a specific class(MYLOGGER) within the specified memory location.
 
May be something like this would help?
Code:
interface 
....
function CreateOrOpenMemShare():Boolean;
...
var
  hMappedFile    : Cardinal = 0;
  MappingExists  : Boolean  = False;
  SharedObject   : TMyObject = nil;

implementation

function CreateOrOpenMemShare():Boolean;
var
  NewlyCreated : Boolean;
begin
  Result := False;
  hMappedFile := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TMyObject), pChar('MemShareName'));
  if (hMappedFile <> 0) then
  begin
    NewlyCreated := (GetLastError <> ERROR_ALREADY_EXISTS);
    SharedObject := MapViewOfFile(hMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
    Result := Assigned(SharedObject);
    MappingExists := Result;
    if (Result and NewlyCreated) then
     SharedObject := TMyObject.Create();
  end;
end;
HTH

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top