Ansistrings DLL/DSO hack (memory manager)

classic Classic list List threaded Threaded
1 message Options
L-9
Reply | Threaded
Open this post in threaded view
|

Ansistrings DLL/DSO hack (memory manager)

L-9
Trustmaster sends me this 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 wrong with it?
i.e. the ability to use strings in a DLL/DSO without ever using Pchars.


Trustmaster's 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 using this tactic, and see what happens with this sort of set up.
When
using no shared memory manager and using strings, PasForum would run but random
access violations would occur every so often. I assume this is why the PSP4UM has
been running without issue for several while now, because it does work, sort of, to
not use a shared memory manager - it's just risky and can cause access violations,
and obviously not worth trying for too long.

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