cmem.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. Function Malloc (Size : Longint) : Pointer;cdecl; external 'c' name 'malloc';
  17. Procedure Free (P : pointer); cdecl; external 'c' name 'free';
  18. Procedure FreeMem (P : Pointer); cdecl; external 'c' name 'free';
  19. function ReAlloc (P : Pointer; Size : longint) : pointer; cdecl; external 'c' name 'realloc';
  20. Function CAlloc (unitSize,UnitCount : Longint) : pointer;cdecl;external 'c' name 'calloc';
  21. implementation
  22. Function CGetMem (Size : Longint) : Pointer;
  23. begin
  24. result:=Malloc(Size);
  25. end;
  26. Function CFreeMem (Var P : pointer) : Longint;
  27. begin
  28. Free(P);
  29. Result:=0;
  30. end;
  31. Function CFreeMemSize(var p:pointer;Size:Longint):Longint;
  32. begin
  33. Result:=CFreeMem(P);
  34. end;
  35. Function CAllocMem(Size : Longint) : Pointer;
  36. begin
  37. Result:=calloc(Size,1);
  38. end;
  39. Function CReAllocMem (var p:pointer;Size:longint):Pointer;
  40. begin
  41. p := realloc(p,size);
  42. Result:=p;
  43. end;
  44. Function CMemSize (p:pointer): Longint;
  45. begin
  46. Result:=0;
  47. end;
  48. Function CMemAvail : Longint;
  49. begin
  50. Result:=0;
  51. end;
  52. Function CMaxAvail: Longint;
  53. begin
  54. Result:=0;
  55. end;
  56. Function CHeapSize : Longint;
  57. begin
  58. Result:=0;
  59. end;
  60. Const
  61. CMemoryManager : TMemoryManager =
  62. (
  63. GetMem : {$ifdef fpc}@{$endif}CGetmem;
  64. FreeMem : {$ifdef fpc}@{$endif}CFreeMem;
  65. FreememSize : {$ifdef fpc}@{$endif}CFreememSize;
  66. AllocMem : {$ifdef fpc}@{$endif}CAllocMem;
  67. ReallocMem : {$ifdef fpc}@{$endif}CReAllocMem;
  68. MemSize : {$ifdef fpc}@{$endif}CMemSize;
  69. MemAvail : {$ifdef fpc}@{$endif fpc}CMemAvail;
  70. MaxAvail : {$ifdef fpc}@{$endif}MaxAvail;
  71. HeapSize : {$ifdef fpc}@{$endif}CHeapSize;
  72. );
  73. Var
  74. OldMemoryManager : TMemoryManager;
  75. Initialization
  76. GetMemoryManager (OldMemoryManager);
  77. SetMemoryManager (CmemoryManager);
  78. Finalization
  79. SetMemoryManager (OldMemoryManager);
  80. end.
  81. {
  82. $Log$
  83. Revision 1.5 2001-10-23 12:14:36 jonas
  84. * fixed CReAllocMem (web bug 1637)
  85. Revision 1.4 2001/06/07 16:34:41 jonas
  86. * added ifdef fpc round @ for procvars
  87. Revision 1.3 2001/06/07 16:14:48 marco
  88. * Fixed @ procvar
  89. Revision 1.2 2000/07/13 11:33:10 michael
  90. + removed logs
  91. }