cmem.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Result:=realloc(p,size);
  42. end;
  43. Function CMemSize (p:pointer): Longint;
  44. begin
  45. Result:=0;
  46. end;
  47. Function CMemAvail : Longint;
  48. begin
  49. Result:=0;
  50. end;
  51. Function CMaxAvail: Longint;
  52. begin
  53. Result:=0;
  54. end;
  55. Function CHeapSize : Longint;
  56. begin
  57. Result:=0;
  58. end;
  59. Const
  60. CMemoryManager : TMemoryManager =
  61. (
  62. GetMem : CGetmem;
  63. FreeMem : CFreeMem;
  64. FreememSize : CFreememSize;
  65. AllocMem : CAllocMem;
  66. ReallocMem : CReAllocMem;
  67. MemSize : CMemSize;
  68. MemAvail : CMemAvail;
  69. MaxAvail : MaxAvail;
  70. HeapSize : CHeapSize;
  71. );
  72. Var
  73. OldMemoryManager : TMemoryManager;
  74. Initialization
  75. GetMemoryManager (OldMemoryManager);
  76. SetMemoryManager (CmemoryManager);
  77. Finalization
  78. SetMemoryManager (OldMemoryManager);
  79. end. $Log$
  80. end. Revision 1.2 2000-07-13 11:33:10 michael
  81. end. + removed logs
  82. end.
  83. }