heaph.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. THeapStatus = record
  15. MaxHeapSize,
  16. MaxHeapUsed,
  17. CurrHeapSize,
  18. CurrHeapUsed,
  19. CurrHeapFree : ptrint;
  20. end;
  21. PMemoryManager = ^TMemoryManager;
  22. TMemoryManager = record
  23. NeedLock : boolean;
  24. Getmem : Function(Size:ptrint):Pointer;
  25. Freemem : Function(p:pointer):ptrint;
  26. FreememSize : Function(p:pointer;Size:ptrint):ptrint;
  27. AllocMem : Function(Size:ptrint):Pointer;
  28. ReAllocMem : Function(var p:pointer;Size:ptrint):Pointer;
  29. MemSize : function(p:pointer):ptrint;
  30. GetHeapStatus : procedure(var status:THeapStatus);
  31. end;
  32. TMemoryMutexManager = record
  33. MutexInit : procedure;
  34. MutexDone : procedure;
  35. MutexLock : procedure;
  36. MutexUnlock : procedure;
  37. end;
  38. procedure GetMemoryManager(var MemMgr: TMemoryManager);
  39. procedure SetMemoryManager(const MemMgr: TMemoryManager);
  40. function IsMemoryManagerSet: Boolean;
  41. procedure SetMemoryMutexManager(var MutexMgr: TMemoryMutexManager);
  42. { Variables }
  43. const
  44. growheapsizesmall : ptrint=32*1024; { fixed-size small blocks will grow with 32k }
  45. growheapsize1 : ptrint=256*1024; { < 256k will grow with 256k }
  46. growheapsize2 : ptrint=1024*1024; { > 256k will grow with 1m }
  47. var
  48. ReturnNilIfGrowHeapFails : boolean;
  49. { Default MemoryManager functions }
  50. Function SysGetmem(Size:ptrint):Pointer;
  51. Function SysFreemem(p:pointer):ptrint;
  52. Function SysFreememSize(p:pointer;Size:ptrint):ptrint;
  53. Function SysMemSize(p:pointer):ptrint;
  54. Function SysAllocMem(size:ptrint):Pointer;
  55. function SysTryResizeMem(var p:pointer;size : ptrint):boolean;
  56. Function SysReAllocMem(var p:pointer;size:ptrint):Pointer;
  57. procedure SysGetHeapStatus(var status:THeapStatus);
  58. { Tp7 functions }
  59. Procedure Getmem(Var p:pointer;Size:ptrint);
  60. Procedure Getmemory(Var p:pointer;Size:ptrint);
  61. Procedure Freemem(p:pointer;Size:ptrint);
  62. Procedure Freememory(p:pointer;Size:ptrint);
  63. { FPC additions }
  64. Function MemSize(p:pointer):ptrint;
  65. { Delphi functions }
  66. function GetMem(size:ptrint):pointer;
  67. function GetMemory(size:ptrint):pointer;
  68. function Freemem(p:pointer):ptrint;
  69. function Freememory(p:pointer):ptrint;
  70. function AllocMem(Size:ptrint):pointer;
  71. function ReAllocMem(var p:pointer;Size:ptrint):pointer;
  72. function ReAllocMemory(var p:pointer;Size:ptrint):pointer;
  73. procedure GetHeapStatus(var status:THeapStatus);
  74. {$ifndef ValueGetmem}
  75. { Needed to solve overloading problem with call from assembler (PFV) }
  76. Procedure AsmGetmem(var p:pointer;size:ptrint);
  77. {$endif ValueGetmem}
  78. {$ifndef ValueFreemem}
  79. Procedure AsmFreemem(var p:pointer);
  80. {$endif ValueFreemem}
  81. { Bootstrapping }
  82. {$ifndef HASGETHEAPSTATUS}
  83. Function Memavail:ptrint;
  84. Function Maxavail:ptrint;
  85. Function Heapsize:ptrint;
  86. {$endif HASGETHEAPSTATUS}
  87. {
  88. $Log$
  89. Revision 1.12 2004-11-22 19:34:58 peter
  90. * GetHeapStatus added, removed MaxAvail,MemAvail,HeapSize
  91. Revision 1.11 2004/06/29 20:50:32 peter
  92. * readded support for ReturnIfGrowHeapFails
  93. Revision 1.10 2004/06/20 09:24:40 peter
  94. fixed go32v2 compile
  95. Revision 1.9 2004/06/17 16:16:13 peter
  96. * New heapmanager that releases memory back to the OS, donated
  97. by Micha Nelissen
  98. Revision 1.8 2004/03/15 21:48:26 peter
  99. * cmem moved to rtl
  100. * longint replaced with ptrint in heapmanagers
  101. Revision 1.7 2003/10/02 14:03:24 marco
  102. * *memORY overloads
  103. Revision 1.6 2002/10/30 20:39:13 peter
  104. * MemoryManager record has a field NeedLock if the wrapper functions
  105. need to provide locking for multithreaded programs
  106. Revision 1.5 2002/10/14 19:39:17 peter
  107. * threads unit added for thread support
  108. Revision 1.4 2002/09/07 15:07:45 peter
  109. * old logs removed and tabs fixed
  110. }