cmem.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. LibName = 'c';
  19. {$else}
  20. LibName = 'msvcrt';
  21. {$endif}
  22. Function Malloc (Size : Longint) : Pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'malloc';
  23. Procedure Free (P : pointer); {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'free';
  24. function ReAlloc (P : Pointer; Size : longint) : pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'realloc';
  25. Function CAlloc (unitSize,UnitCount : Longint) : pointer; {$ifdef win32}stdcall{$else}cdecl{$endif}; external LibName name 'calloc';
  26. implementation
  27. Function CGetMem (Size : Longint) : Pointer;
  28. begin
  29. result:=Malloc(Size);
  30. end;
  31. Function CFreeMem ({$ifdef VER1_0}var{$endif} P : pointer) : Longint;
  32. begin
  33. Free(P);
  34. Result:=0;
  35. end;
  36. Function CFreeMemSize({$ifdef VER1_0}var{$endif} p:pointer;Size:Longint):Longint;
  37. begin
  38. Result:=CFreeMem(P);
  39. end;
  40. Function CAllocMem(Size : Longint) : Pointer;
  41. begin
  42. Result:=calloc(Size,1);
  43. end;
  44. Function CReAllocMem (var p:pointer;Size:longint):Pointer;
  45. begin
  46. p := realloc(p,size);
  47. Result:=p;
  48. end;
  49. Function CMemSize (p:pointer): Longint;
  50. begin
  51. Result:=0;
  52. end;
  53. Function CMemAvail : Longint;
  54. begin
  55. Result:=0;
  56. end;
  57. Function CMaxAvail: Longint;
  58. begin
  59. Result:=0;
  60. end;
  61. Function CHeapSize : Longint;
  62. begin
  63. Result:=0;
  64. end;
  65. Const
  66. CMemoryManager : TMemoryManager =
  67. (
  68. {$ifndef VER1_0}
  69. NeedLock : false;
  70. {$endif VER1_0}
  71. GetMem : {$ifdef fpc}@{$endif}CGetmem;
  72. FreeMem : {$ifdef fpc}@{$endif}CFreeMem;
  73. FreememSize : {$ifdef fpc}@{$endif}CFreememSize;
  74. AllocMem : {$ifdef fpc}@{$endif}CAllocMem;
  75. ReallocMem : {$ifdef fpc}@{$endif}CReAllocMem;
  76. MemSize : {$ifdef fpc}@{$endif}CMemSize;
  77. MemAvail : {$ifdef fpc}@{$endif fpc}CMemAvail;
  78. MaxAvail : {$ifdef fpc}@{$endif}MaxAvail;
  79. HeapSize : {$ifdef fpc}@{$endif}CHeapSize;
  80. );
  81. Var
  82. OldMemoryManager : TMemoryManager;
  83. Initialization
  84. GetMemoryManager (OldMemoryManager);
  85. SetMemoryManager (CmemoryManager);
  86. Finalization
  87. SetMemoryManager (OldMemoryManager);
  88. end.
  89. {
  90. $Log$
  91. Revision 1.7 2002-11-01 17:56:39 peter
  92. * needlock field added for 1.1
  93. Revision 1.6 2002/09/08 15:43:47 michael
  94. + Fixed calling conventions
  95. Revision 1.5 2002/09/07 15:42:54 peter
  96. * old logs removed and tabs fixed
  97. Revision 1.4 2002/07/01 16:24:04 peter
  98. * updates for 1.0 compiler
  99. Revision 1.3 2002/06/13 05:01:44 michael
  100. + Added windows msvcrt support
  101. Revision 1.2 2002/06/13 04:54:47 michael
  102. + Fixed parameter type mismatch
  103. Revision 1.1 2002/01/29 17:54:59 peter
  104. * splitted to base and extra
  105. }