heaph.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Freemem(p:pointer;Size:Longint);
  58. Function memavail:Longint;
  59. Function maxavail:Longint;
  60. { FPC additions }
  61. Function MemSize(p:pointer):Longint;
  62. Function heapsize:longint;
  63. { Delphi functions }
  64. function GetMem(size:longint):pointer;
  65. function Freemem(p:pointer):longint;
  66. function AllocMem(Size:Longint):pointer;
  67. function ReAllocMem(var p:pointer;Size:Longint):pointer;
  68. { Do nothing functions, are only here for tp7 compat }
  69. Procedure mark(var p : pointer);
  70. Procedure release(var p : pointer);
  71. {$ifndef ValueGetmem}
  72. { Needed to solve overloading problem with call from assembler (PFV) }
  73. Procedure AsmGetmem(var p:pointer;size:Longint);
  74. {$endif ValueGetmem}
  75. {$ifndef ValueFreemem}
  76. Procedure AsmFreemem(var p:pointer);
  77. {$endif ValueFreemem}
  78. {
  79. $Log$
  80. Revision 1.6 2002-10-30 20:39:13 peter
  81. * MemoryManager record has a field NeedLock if the wrapper functions
  82. need to provide locking for multithreaded programs
  83. Revision 1.5 2002/10/14 19:39:17 peter
  84. * threads unit added for thread support
  85. Revision 1.4 2002/09/07 15:07:45 peter
  86. * old logs removed and tabs fixed
  87. }