heaph.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Heap manager interface section
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { Memorymanager }
  13. type
  14. {$ifdef HASGETFPCHEAPSTATUS}
  15. TFPCHeapStatus = record
  16. MaxHeapSize,
  17. MaxHeapUsed,
  18. CurrHeapSize,
  19. CurrHeapUsed,
  20. CurrHeapFree : ptrint;
  21. end;
  22. THeapStatus = record
  23. TotalAddrSpace: Cardinal;
  24. TotalUncommitted: Cardinal;
  25. TotalCommitted: Cardinal;
  26. TotalAllocated: Cardinal;
  27. TotalFree: Cardinal;
  28. FreeSmall: Cardinal;
  29. FreeBig: Cardinal;
  30. Unused: Cardinal;
  31. Overhead: Cardinal;
  32. HeapErrorCode: Cardinal;
  33. end;
  34. {$else HASGETFPCHEAPSTATUS}
  35. THeapStatus = record
  36. MaxHeapSize,
  37. MaxHeapUsed,
  38. CurrHeapSize,
  39. CurrHeapUsed,
  40. CurrHeapFree : ptrint;
  41. end;
  42. {$endif HASGETFPCHEAPSTATUS}
  43. PMemoryManager = ^TMemoryManager;
  44. TMemoryManager = record
  45. NeedLock : boolean;
  46. Getmem : Function(Size:ptrint):Pointer;
  47. Freemem : Function(p:pointer):ptrint;
  48. FreememSize : Function(p:pointer;Size:ptrint):ptrint;
  49. AllocMem : Function(Size:ptrint):Pointer;
  50. ReAllocMem : Function(var p:pointer;Size:ptrint):Pointer;
  51. MemSize : function(p:pointer):ptrint;
  52. {$ifdef HASGETFPCHEAPSTATUS}
  53. GetHeapStatus : function :THeapStatus;
  54. GetFPCHeapStatus : function :TFPCHeapStatus;
  55. {$else HASGETFPCHEAPSTATUS}
  56. GetHeapStatus : procedure(var status:THeapStatus);
  57. {$endif HASGETFPCHEAPSTATUS}
  58. end;
  59. TMemoryMutexManager = record
  60. MutexInit : procedure;
  61. MutexDone : procedure;
  62. MutexLock : procedure;
  63. MutexUnlock : procedure;
  64. end;
  65. procedure GetMemoryManager(var MemMgr: TMemoryManager);
  66. procedure SetMemoryManager(const MemMgr: TMemoryManager);
  67. function IsMemoryManagerSet: Boolean;
  68. procedure SetMemoryMutexManager(var MutexMgr: TMemoryMutexManager);
  69. { Variables }
  70. const
  71. growheapsizesmall : ptrint=32*1024; { fixed-size small blocks will grow with 32k }
  72. growheapsize1 : ptrint=256*1024; { < 256k will grow with 256k }
  73. growheapsize2 : ptrint=1024*1024; { > 256k will grow with 1m }
  74. var
  75. ReturnNilIfGrowHeapFails : boolean;
  76. { Default MemoryManager functions }
  77. Function SysGetmem(Size:ptrint):Pointer;
  78. Function SysFreemem(p:pointer):ptrint;
  79. Function SysFreememSize(p:pointer;Size:ptrint):ptrint;
  80. Function SysMemSize(p:pointer):ptrint;
  81. Function SysAllocMem(size:ptrint):Pointer;
  82. function SysTryResizeMem(var p:pointer;size : ptrint):boolean;
  83. Function SysReAllocMem(var p:pointer;size:ptrint):Pointer;
  84. {$ifdef HASGETFPCHEAPSTATUS}
  85. function SysGetHeapStatus:THeapStatus;
  86. function SysGetFPCHeapStatus:TFPCHeapStatus;
  87. {$else}
  88. procedure SysGetHeapStatus(var status:THeapStatus);
  89. {$endif HASGETFPCHEAPSTATUS}
  90. { Tp7 functions }
  91. Procedure Getmem(Var p:pointer;Size:ptrint);
  92. Procedure Getmemory(Var p:pointer;Size:ptrint);
  93. Procedure Freemem(p:pointer;Size:ptrint);
  94. Procedure Freememory(p:pointer;Size:ptrint);
  95. { FPC additions }
  96. Function MemSize(p:pointer):ptrint;
  97. { Delphi functions }
  98. function GetMem(size:ptrint):pointer;
  99. function GetMemory(size:ptrint):pointer;
  100. function Freemem(p:pointer):ptrint;
  101. function Freememory(p:pointer):ptrint;
  102. function AllocMem(Size:ptrint):pointer;
  103. function ReAllocMem(var p:pointer;Size:ptrint):pointer;
  104. function ReAllocMemory(var p:pointer;Size:ptrint):pointer;
  105. {$ifdef HASGETFPCHEAPSTATUS}
  106. function GetHeapStatus:THeapStatus;
  107. function GetFPCHeapStatus:TFPCHeapStatus;
  108. {$else}
  109. procedure GetHeapStatus(var status:THeapStatus);
  110. {$endif HASGETFPCHEAPSTATUS}
  111. {$ifndef ValueGetmem}
  112. { Needed to solve overloading problem with call from assembler (PFV) }
  113. Procedure AsmGetmem(var p:pointer;size:ptrint);
  114. {$endif ValueGetmem}
  115. {$ifndef ValueFreemem}
  116. Procedure AsmFreemem(var p:pointer);
  117. {$endif ValueFreemem}
  118. { Bootstrapping }
  119. {$ifndef HASGETHEAPSTATUS}
  120. Function Memavail:ptrint;
  121. Function Maxavail:ptrint;
  122. Function Heapsize:ptrint;
  123. {$endif HASGETHEAPSTATUS}
  124. {
  125. $Log$
  126. Revision 1.15 2005-03-04 16:49:34 peter
  127. * fix getheapstatus bootstrapping
  128. Revision 1.14 2005/02/28 15:38:38 marco
  129. * getFPCheapstatus (no, FPC HEAP, not FP CHEAP!)
  130. Revision 1.13 2005/02/14 17:13:22 peter
  131. * truncate log
  132. }