Memory manager replacement using the C memory manager

The cmem memory manager sets the system units memory manager to a C-based memory manager: all memory management calls are shunted through to the C memory manager, using , and . For this reason, the cmem unit should be the first unit of the uses clause of the program.

The unit also offers the C memory calls directly as external declarations from the C library, but it is recommended to use the normal FPC routines for this.

Obviously, including this unit links your program to the C library.

Name of the library used LibName is the name of the library that is actually used. On most systems, this is simply "libc.so". Malloc external declaration. Malloc is the external declaration of the C librarys malloc call. It accepts a size parameter, and returns a pointer to a memory block of the requested size or Nil if no more memory could be allocated. A pointer to the newly allocated memory block Requested size for the new memory block. Free a previously allocated block Free returns the memory block pointed to by P to the system. After Free was called, the pointer P is no longer valid. Pointer to the memory block to be freed. Reallocates a memory block ReAlloc re-allocates a block of memory pointed to by p. The new block will have size Size, and as much data as was available or as much data as fits is copied from the old to the new location. A pointer to the new memory block Pointer to the old block New size for the memory block. Allocate memory based on item size and count Calloc allocates memory to hold UnitCount units of size UnitSize each. The memory is one block of memory. It returns a pointer to the newly allocated memory block. Pointer to the newly allocated memory block. Size of one unit. Number of units.