Difference between revisions of "CMem"

From Lazarus wiki
Jump to navigationJump to search
m (Fix typo)
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
The unit should be the first unit in the uses clause, otherwise memory can already be allocated by initialization routines in units that are initialized before the C memory manager is installed.
 
The unit should be the first unit in the uses clause, otherwise memory can already be allocated by initialization routines in units that are initialized before the C memory manager is installed.
  
In cases where several units like cthreads, cmem and cwstrings are recommended to be placed first, due to how the units work a sensible order is cmem, cthreads and then cwstrings.
+
In cases where several units like '''cthreads''', '''cmem''' and '''cwstrings''' are recommended to be placed first, due to how the units work a sensible order is
  
There is a small example program '''testcmem''', which demonstrates the use of the cmem unit.
+
* cmem
 +
* cthreads
 +
* cwstrings
 +
 
 +
There is a small example program [https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/libgc/examples/testcmem.pp '''testcmem'''], which demonstrates the use of the cmem unit.
  
 
CMem should not be used if [[heaptrc]] is used.
 
CMem should not be used if [[heaptrc]] is used.

Latest revision as of 20:40, 10 January 2022

Deutsch (de) English (en)

If you include the cmem unit in your uses clause of your program, it will replace the native Free Pascal memory manager with the C library memory manager. All memory management is then done by the C memory manager.

The unit should be the first unit in the uses clause, otherwise memory can already be allocated by initialization routines in units that are initialized before the C memory manager is installed.

In cases where several units like cthreads, cmem and cwstrings are recommended to be placed first, due to how the units work a sensible order is

  • cmem
  • cthreads
  • cwstrings

There is a small example program testcmem, which demonstrates the use of the cmem unit.

CMem should not be used if heaptrc is used.