summaryrefslogtreecommitdiff
path: root/fpcsrc/rtl/inc/heaph.inc
blob: 304d9e80c42b5240aaffc90f641d54d2e4b1d053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 1999-2000 by the Free Pascal development team

    Heap manager interface section

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{ Memorymanager }
type
  TFPCHeapStatus = record
    MaxHeapSize,
    MaxHeapUsed,
    CurrHeapSize,
    CurrHeapUsed,
    CurrHeapFree  : ptruint;
  end;
  THeapStatus = record
    TotalAddrSpace: Cardinal;
    TotalUncommitted: Cardinal;
    TotalCommitted: Cardinal;
    TotalAllocated: Cardinal;
    TotalFree: Cardinal;
    FreeSmall: Cardinal;
    FreeBig: Cardinal;
    Unused: Cardinal;
    Overhead: Cardinal;
    HeapErrorCode: Cardinal;
  end;

  PMemoryManager = ^TMemoryManager;
  TMemoryManager = record
    NeedLock            : boolean;   // Obsolete
    Getmem              : Function(Size:ptruint):Pointer;
    Freemem             : Function(p:pointer):ptruint;
    FreememSize         : Function(p:pointer;Size:ptruint):ptruint;
    AllocMem            : Function(Size:ptruint):Pointer;
    ReAllocMem          : Function(var p:pointer;Size:ptruint):Pointer;
    MemSize             : function(p:pointer):ptruint;
    InitThread          : procedure;
    DoneThread          : procedure;
    RelocateHeap        : procedure;
    GetHeapStatus       : function :THeapStatus;
    GetFPCHeapStatus    : function :TFPCHeapStatus;
  end;

procedure GetMemoryManager(var MemMgr: TMemoryManager);
procedure SetMemoryManager(const MemMgr: TMemoryManager);
function  IsMemoryManagerSet: Boolean;

{ Variables }
const
  MaxKeptOSChunks: DWord = 4; { if more than MaxKeptOSChunks are free, the heap manager will release
                              chunks back to the OS }
  growheapsizesmall : ptruint=32*1024; { fixed-size small blocks will grow with 32k }
  growheapsize1 : ptruint=256*1024;  { < 256k will grow with 256k }
  growheapsize2 : ptruint=1024*1024; { > 256k will grow with 1m }
var
  ReturnNilIfGrowHeapFails : boolean;

{ Default MemoryManager functions }
Function  SysGetmem(Size:ptruint):Pointer;
Function  SysFreemem(p:pointer):ptruint;
Function  SysFreememSize(p:pointer;Size:ptruint):ptruint;
Function  SysMemSize(p:pointer):ptruint;
Function  SysAllocMem(size:ptruint):Pointer;
function  SysTryResizeMem(var p:pointer;size:ptruint):boolean;
Function  SysReAllocMem(var p:pointer;size:ptruint):Pointer;
function  SysGetHeapStatus:THeapStatus;
function  SysGetFPCHeapStatus:TFPCHeapStatus;

{ Tp7 functions }
Procedure Getmem(Out p:pointer;Size:ptruint);
Procedure Getmemory(Out p:pointer;Size:ptruint);
Procedure Freemem(p:pointer;Size:ptruint);
Procedure Freememory(p:pointer;Size:ptruint);

{ FPC additions }
Function  MemSize(p:pointer):ptruint;

{ Delphi functions }
function GetMem(size:ptruint):pointer;
function GetMemory(size:ptruint):pointer; cdecl;
function Freemem(p:pointer):ptruint;
function Freememory(p:pointer):ptruint; cdecl;
function AllocMem(Size:ptruint):pointer;
function ReAllocMem(var p:pointer;Size:ptruint):pointer;
function ReAllocMemory(p:pointer;Size:ptruint):pointer; cdecl;
function GetHeapStatus:THeapStatus;
function GetFPCHeapStatus:TFPCHeapStatus;

{ Bootstrapping }