2
0

heaph.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Heap manager interface section
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Memorymanager }
  12. type
  13. TFPCHeapStatus = record
  14. MaxHeapSize,
  15. MaxHeapUsed,
  16. CurrHeapSize,
  17. CurrHeapUsed,
  18. CurrHeapFree : ptruint;
  19. end;
  20. THeapStatus = record
  21. TotalAddrSpace: Cardinal;
  22. TotalUncommitted: Cardinal;
  23. TotalCommitted: Cardinal;
  24. TotalAllocated: Cardinal;
  25. TotalFree: Cardinal;
  26. FreeSmall: Cardinal;
  27. FreeBig: Cardinal;
  28. Unused: Cardinal;
  29. Overhead: Cardinal;
  30. HeapErrorCode: Cardinal;
  31. end;
  32. PMemoryManager = ^TMemoryManager;
  33. TMemoryManager = record
  34. NeedLock : boolean; // Obsolete
  35. Getmem : Function(Size:ptruint):Pointer;
  36. Freemem : Function(p:pointer):ptruint;
  37. FreememSize : Function(p:pointer;Size:ptruint):ptruint;
  38. AllocMem : Function(Size:ptruint):Pointer;
  39. ReAllocMem : Function(var p:pointer;Size:ptruint):Pointer;
  40. MemSize : function(p:pointer):ptruint;
  41. InitThread : procedure;
  42. DoneThread : procedure;
  43. RelocateHeap : procedure;
  44. GetHeapStatus : function :THeapStatus;
  45. GetFPCHeapStatus : function :TFPCHeapStatus;
  46. end;
  47. procedure GetMemoryManager(var MemMgr: TMemoryManager);
  48. procedure SetMemoryManager(const MemMgr: TMemoryManager);
  49. function IsMemoryManagerSet: Boolean;
  50. { Variables }
  51. const
  52. MaxKeptOSChunks: DWord = 4; { if more than MaxKeptOSChunks are free, the heap manager will release
  53. chunks back to the OS }
  54. growheapsizesmall : ptruint=32*1024; { fixed-size small blocks will grow with 32k }
  55. growheapsize1 : ptruint=256*1024; { < 256k will grow with 256k }
  56. growheapsize2 : ptruint=1024*1024; { > 256k will grow with 1m }
  57. var
  58. ReturnNilIfGrowHeapFails : boolean;
  59. {$ifdef EMBEDDED}
  60. {$define FPC_NO_DEFAULT_MEMORYMANAGER}
  61. {$endif EMBEDDED}
  62. {$ifndef FPC_NO_DEFAULT_MEMORYMANAGER}
  63. { Default MemoryManager functions }
  64. Function SysGetmem(Size:ptruint):Pointer;
  65. Function SysFreemem(p:pointer):ptruint;
  66. Function SysFreememSize(p:pointer;Size:ptruint):ptruint;
  67. Function SysMemSize(p:pointer):ptruint;
  68. Function SysAllocMem(size:ptruint):Pointer;
  69. function SysTryResizeMem(var p:pointer;size:ptruint):boolean;
  70. Function SysReAllocMem(var p:pointer;size:ptruint):Pointer;
  71. function SysGetHeapStatus:THeapStatus;
  72. function SysGetFPCHeapStatus:TFPCHeapStatus;
  73. {$endif FPC_NO_DEFAULT_MEMORYMANAGER}
  74. {$ifdef FPC_HAS_FEATURE_HEAP}
  75. { Tp7 functions }
  76. Procedure Getmem(Out p:pointer;Size:ptruint);
  77. Procedure Getmemory(Out p:pointer;Size:ptruint);
  78. Procedure Freemem(p:pointer;Size:ptruint);
  79. Procedure Freememory(p:pointer;Size:ptruint);
  80. { FPC additions }
  81. Function MemSize(p:pointer):ptruint;
  82. { Delphi functions }
  83. function GetMem(size:ptruint):pointer;
  84. function GetMemory(size:ptruint):pointer; cdecl;
  85. function Freemem(p:pointer):ptruint;
  86. function Freememory(p:pointer):ptruint; cdecl;
  87. function AllocMem(Size:ptruint):pointer;
  88. function ReAllocMem(var p:pointer;Size:ptruint):pointer;
  89. function ReAllocMemory(p:pointer;Size:ptruint):pointer; cdecl;
  90. function GetHeapStatus:THeapStatus;
  91. function GetFPCHeapStatus:TFPCHeapStatus;
  92. {$endif FPC_HAS_FEATURE_HEAP}