A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

Sharing Memory Via DLL


Use getmemorymanager and use the memory manager in the DLL. Share the exe memory manager with the executable. No need for an extra memory manager since you are using an already existing one.

Each module has it's own memory manager. That is why ansistrings can not be exported from functions without sharing memory. To get ansistrings working in a dll, the trick is to export the memory manager from the dll first through a procedure and a buffer parameter which holds the memory manager for the exe to hook up with.

With delphi, this trick means you do not use borlandsharemem borlandmm or sharemem of any sort, to use ansi strings in dll's.

On freepascal it means no need to use CMEM.pp.


Code came from Trustmaster:
// psplib.pp
{$H+}
{$MODE OBJFPC}
{$SMARTLINK OFF}
library psplib;
{ ... }
procedure GetMemMan (out MemMan : TMemoryManager); stdcall; export;
begin
    GetMemoryManager (MemMan)
end;
{ ... }
exports
{ ... }
  GetMemMan name 'GetSharedMemoryManager';
{ ... }
end.

// pspunit.pp
{$H+}
{$MODE OBJFPC}
{$SMARTLINK OFF}
unit pspunit;
interface
{ ... }
implementation
{ ... }
procedure GetMemMan (out MemMan : TMemoryManager); stdcall;  external 'psplib' 
name 'GetSharedMemoryManager';
var MemMan : TMemoryManager;
{ ... }
initialization
    GetMemMan(MemMan);
    SetMemoryManager (MemMan);
{ ... }
end.

// pspapp.pp
{$H+}
{$MODE OBJFPC}
program pspapp;
uses pspunit;
{ ... }
begin
{ ... }
end.



About
This site is about programming and other things.
_ _ _