heaph.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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:Longint):Pointer;
  18. Freemem : Function(p:pointer):Longint;
  19. FreememSize : Function(p:pointer;Size:Longint):Longint;
  20. AllocMem : Function(Size:longint):Pointer;
  21. ReAllocMem : Function(var p:pointer;Size:longint):Pointer;
  22. MemSize : function(p:pointer):Longint;
  23. MemAvail : Function:Longint;
  24. MaxAvail : Function:Longint;
  25. HeapSize : Function:Longint;
  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. growheapsize1 : longint=256*1024; { < 256k will grow with 256k }
  40. growheapsize2 : longint=1024*1024; { > 256k will grow with 1m }
  41. ReturnNilIfGrowHeapFails : boolean = false;
  42. var
  43. heaporg,heapptr,heapend,heaperror,freelist : pointer;
  44. { Default MemoryManager functions }
  45. Function SysGetmem(Size:Longint):Pointer;
  46. Function SysFreemem(p:pointer):Longint;
  47. Function SysFreememSize(p:pointer;Size:Longint):Longint;
  48. Function SysMemSize(p:pointer):Longint;
  49. Function SysAllocMem(size:longint):Pointer;
  50. function SysTryResizeMem(var p:pointer;size : longint):boolean;
  51. Function SysReAllocMem(var p:pointer;size:longint):Pointer;
  52. Function Sysmemavail:Longint;
  53. Function Sysmaxavail:Longint;
  54. Function Sysheapsize:longint;
  55. { Tp7 functions }
  56. Procedure Getmem(Var p:pointer;Size:Longint);
  57. Procedure Getmemory(Var p:pointer;Size:Longint);
  58. Procedure Freemem(p:pointer;Size:Longint);
  59. Procedure Freememory(p:pointer;Size:Longint);
  60. Function memavail:Longint;
  61. Function maxavail:Longint;
  62. { FPC additions }
  63. Function MemSize(p:pointer):Longint;
  64. Function heapsize:longint;
  65. { Delphi functions }
  66. function GetMem(size:longint):pointer;
  67. function GetMemory(size:longint):pointer;
  68. function Freemem(p:pointer):longint;
  69. function Freememory(p:pointer):longint;
  70. function AllocMem(Size:Longint):pointer;
  71. function ReAllocMem(var p:pointer;Size:Longint):pointer;
  72. function ReAllocMemory(var p:pointer;Size:Longint):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:Longint);
  79. {$endif ValueGetmem}
  80. {$ifndef ValueFreemem}
  81. Procedure AsmFreemem(var p:pointer);
  82. {$endif ValueFreemem}
  83. {
  84. $Log$
  85. Revision 1.7 2003-10-02 14:03:24 marco
  86. * *memORY overloads
  87. Revision 1.6 2002/10/30 20:39:13 peter
  88. * MemoryManager record has a field NeedLock if the wrapper functions
  89. need to provide locking for multithreaded programs
  90. Revision 1.5 2002/10/14 19:39:17 peter
  91. * threads unit added for thread support
  92. Revision 1.4 2002/09/07 15:07:45 peter
  93. * old logs removed and tabs fixed
  94. }