cmem.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999 by Michael Van Canneyt, member of the
  5. Free Pascal development team
  6. Implements a memory manager that uses the C memory management.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit cmem;
  14. {$mode objfpc}
  15. interface
  16. Const
  17. {$ifndef win32}
  18. {$ifdef netware}
  19. LibName = 'clib';
  20. {$else}
  21. LibName = 'c';
  22. {$endif}
  23. {$else}
  24. LibName = 'msvcrt';
  25. {$endif}
  26. Function Malloc (Size : Longint) : Pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'malloc';
  27. Procedure Free (P : pointer); {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'free';
  28. function ReAlloc (P : Pointer; Size : longint) : pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'realloc';
  29. Function CAlloc (unitSize,UnitCount : Longint) : pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'calloc';
  30. implementation
  31. Function CGetMem (Size : Longint) : Pointer;
  32. begin
  33. result:=Malloc(Size);
  34. end;
  35. Function CFreeMem ({$ifdef VER1_0}var{$endif} P : pointer) : Longint;
  36. begin
  37. Free(P);
  38. Result:=0;
  39. end;
  40. Function CFreeMemSize({$ifdef VER1_0}var{$endif} p:pointer;Size:Longint):Longint;
  41. begin
  42. Result:=CFreeMem(P);
  43. end;
  44. Function CAllocMem(Size : Longint) : Pointer;
  45. begin
  46. Result:=calloc(Size,1);
  47. end;
  48. Function CReAllocMem (var p:pointer;Size:longint):Pointer;
  49. begin
  50. p := realloc(p,size);
  51. Result:=p;
  52. end;
  53. Function CMemSize (p:pointer): Longint;
  54. begin
  55. Result:=0;
  56. end;
  57. Function CMemAvail : Longint;
  58. begin
  59. Result:=0;
  60. end;
  61. Function CMaxAvail: Longint;
  62. begin
  63. Result:=0;
  64. end;
  65. Function CHeapSize : Longint;
  66. begin
  67. Result:=0;
  68. end;
  69. Const
  70. CMemoryManager : TMemoryManager =
  71. (
  72. {$ifndef VER1_0}
  73. NeedLock : false;
  74. {$endif VER1_0}
  75. GetMem : {$ifdef fpc}@{$endif}CGetmem;
  76. FreeMem : {$ifdef fpc}@{$endif}CFreeMem;
  77. FreememSize : {$ifdef fpc}@{$endif}CFreememSize;
  78. AllocMem : {$ifdef fpc}@{$endif}CAllocMem;
  79. ReallocMem : {$ifdef fpc}@{$endif}CReAllocMem;
  80. MemSize : {$ifdef fpc}@{$endif}CMemSize;
  81. MemAvail : {$ifdef fpc}@{$endif fpc}CMemAvail;
  82. MaxAvail : {$ifdef fpc}@{$endif}MaxAvail;
  83. HeapSize : {$ifdef fpc}@{$endif}CHeapSize;
  84. );
  85. Var
  86. OldMemoryManager : TMemoryManager;
  87. Initialization
  88. GetMemoryManager (OldMemoryManager);
  89. SetMemoryManager (CmemoryManager);
  90. Finalization
  91. SetMemoryManager (OldMemoryManager);
  92. end.
  93. {
  94. $Log$
  95. Revision 1.8 2003-03-17 15:40:05 armin
  96. + LibName for netware
  97. Revision 1.7 2002/11/01 17:56:39 peter
  98. * needlock field added for 1.1
  99. Revision 1.6 2002/09/08 15:43:47 michael
  100. + Fixed calling conventions
  101. Revision 1.5 2002/09/07 15:42:54 peter
  102. * old logs removed and tabs fixed
  103. Revision 1.4 2002/07/01 16:24:04 peter
  104. * updates for 1.0 compiler
  105. Revision 1.3 2002/06/13 05:01:44 michael
  106. + Added windows msvcrt support
  107. Revision 1.2 2002/06/13 04:54:47 michael
  108. + Fixed parameter type mismatch
  109. Revision 1.1 2002/01/29 17:54:59 peter
  110. * splitted to base and extra
  111. }