heaph.inc 4.0 KB

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