Trustmaster sends me a trick/hack (as shown below) to avoid using CMEM in a
dll/dso in order to get ansistrings working through a dll/dso.

Comments? Find anything that could possibly be wrong with this trick we pull 
off?
i.e. the ability to use strings in a DLL/DSO without ever using Pchars, nor 
CMEM!



The trick/hack:

> Hi Lars,
>
> I've just read an article how to solve the memory management problem with FPC
> without using CMEM unit. It is done by exporting memory manager in the
> library and using it everywhere simply this way:
>
> // psplib.pp
> {$H+}
> {$MODE OBJFPC}
> library psplib;
> { ... }
> procedure GetMemMan (out MemMan : TMemoryManager); stdcall; export;
> begin
>     GetMemoryManager (MemMan)
> end;
> { ... }
> exports
> { ... }
>   GetMemMan name 'GetSharedMemoryManager';
> { ... }
> end.
>
> // pspunit.pp
> {$H+}
> {$MODE OBJFPC}
> 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.


Lars' comments:

Seems to make a simple hello world project with strings in it work as a DLL/DSO 
for
now without requiring Cmem, but further testing will need to be done. I will 
throw up
a PasForum clone (code named Bubble2) using this tactic, and see what happens 
with
this
sort of set up.

When using no shared memory manager and using strings, PasForum (code named 
Bubble)
would
run but random access violations would occur every so often. I assume this is 
why the
PSP4UM (psp.furtopia.org) has been running without issue for several while now,
because it does work,
sort of - but obviously not recommended.

_______________________________________________
fpc-pascal maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to