Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

Using FPC MM in a C program

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to leledumbo
leledumbo wrote 5 lines
Since it's possible to use libc's MM via cmem unit, would the opposite be possible? From the point of view of FPC, there should not be a big problem.

The C library, this is another matter. I am not sure that it supports plugging in a memory manager.

There are many libraries which require you to provide memory managing routines. But as far as I know, this is all done using some macros.

Michael.

Krishna
to Michael Van Canneyt
Michael Van Canneyt wrote 11 lines
On Wed, 31 Dec 2008, leledumbo wrote: > > Since it's possible to use libc's MM via cmem unit, would the opposite be > possible? >From the point of view of FPC, there should not be a big problem. The C library, this is another matter. I am not sure that it supports plugging in a memory manager.

I suppose overriding malloc is enough. I regularly use a non-system memory manager (malloc) even on Windows. btw, has anyone tried jemalloc (used by firefox) with freepascal programs?

Cheers,
-Krishna

Why make things difficult, when it is possible to make them cryptic and totally illogical, with just a little bit more effort? - Aksel Peter Jorgensen
Vinzent Höfler
to Michael Van Canneyt: The C library, this is another matter. I am not sure that it supports plugging in a…
Michael Van Canneyt wrote 9 lines
On Wed, 31 Dec 2008, leledumbo wrote: > Since it's possible to use libc's MM via cmem unit, would the opposite be > possible? > >From the point of view of FPC, there should not be a big problem. The C library, this is another matter. I am not sure that it supports plugging in a memory manager.

Well, if you manage to exchange the standard memory-related subroutines (i.e. malloc() & Co.) from the C-library with your own subroutines, it shouldn't be a problem. But I don't know if that's possible if libc is included in the project. Technically it should if you can convince the linker of doing so. ;)

There are many libraries which require you to provide memory managing routines. But as far as I know, this is all done using some macros.

No, last time I looked, at least in the case of the libpng this is done via real subroutines.

Vinzent.

Michael Van Canneyt
to Vinzent Höfler
Vinzent Höfler wrote 22 lines
Michael Van Canneyt wrote: > > On Wed, 31 Dec 2008, leledumbo wrote: > > > Since it's possible to use libc's MM via cmem unit, would the opposite be > > possible? > > > >From the point of view of FPC, there should not be a big problem. > The C library, this is another matter. I am not sure that it > supports plugging in a memory manager. Well, if you manage to exchange the standard memory-related subroutines (i.e. malloc() & Co.) from the C-library with your own subroutines, it shouldn't be a problem. But I don't know if that's possible if libc is included in the project. Technically it should if you can convince the linker of doing so. ;) > There are many libraries which require you to provide memory managing > routines. > But as far as I know, this is all done using some macros. No, last time I looked, at least in the case of the libpng this is done via real subroutines.

Yes and no;
Sometimes macros are used to 'redirect' malloc() and free() in existing code to the custom routines. It depends on the library.

Michael.

Micha Nelissen
to leledumbo: Since it's possible to use libc's MM via cmem unit, would the opposite be possible? View…
leledumbo wrote
Since it's possible to use libc's MM via cmem unit, would the opposite be possible?

I have a "crtl.pas" which defines a few functions (malloc, calloc, free, memmove, memcpy) to help in using libraries written in C with fpc programs without needing external dependencies (msvcrt.dll on windows, for some reason that did not work for me).

However, it's a all-or-nothing situation. A program uses either this crtl unit, or it links a C library like msvcrt.dll or something similar; using both is asking for trouble.

Micha