Ansistrings DLL/DSO hack (memory manager)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ansistrings DLL/DSO hack (memory manager)

L505
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  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Ansistrings DLL/DSO hack (memory manager)

L505
> I will throw up
> a PasForum clone (code named Bubble2) using this tactic, and see what happens with
> this
> sort of set up.


Here it is:(BUBBLE2)
http://z505.com/cgi-bin/Bubble2/index.psp
Forgive the colors, I haven't played with the CSS file for more than 2 seconds :-)


And the old one which used NO memory manager at all:(BUBBLE1)
http://z505.com/cgi-bin/Bubble/index.psp

And the one that does not use a DLL/DSO so is not worth even discussing, is the
original PasForum so I won't mention the link to there.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Ansistrings DLL/DSO hack (memory manager)

Jonas Maebe-2
In reply to this post by L505

On 25 jan 2006, at 08:39, L505 wrote:

> 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!

It's exactly the same principle as using cmem, just that you are  
using another memory manager than the one of the standard C library.  
It has the same advantages (can return and accept ansistrings to/from  
FPC-compiled programs and libararies) and problems (must not return  
and accept ansistrings to/from programs not compiled with FPC). Well,  
another advantage is of course for OS'es where the interface to libc  
changes all the time (although I doubt the interface to malloc/free  
etc will change anytime soon).


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Ansistrings DLL/DSO hack (memory manager)

L505

Sorry for the double posting, the emails took a long time to get through.

> It's exactly the same principle as using cmem, just that you are
> using another memory manager than the one of the standard C library.
> It has the same advantages (can return and accept ansistrings to/from
> FPC-compiled programs and libararies) and problems (must not return
> and accept ansistrings to/from programs not compiled with FPC). Well,
> another advantage is of course for OS'es where the interface to libc
> changes all the time (although I doubt the interface to malloc/free
> etc will change anytime soon).
>
>

And this case we use FPC mem manager rather than relying on our operating system
friend - just makes me feel better to be able to utilize FPC mem manager if I can!

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