A r t i c l e s
Navigation

Note: This Wiki is
outdated, personal views
may have changed.
L505 A.I. bot is dead
long live THX 1138

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
Note: This Wiki is outdated, personal views may have changed.

This wiki contains info on life, health, humans, nature, programming, database, fads, paradigms, poems, principles, theories.

Articles may contain statements which some may find helpful and encouraging, or even discouraging.

Beware, I believe in the Grand Justice system.
_ _ _