mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-31 10:30:20 +02:00
Add SysTinyGetHeapStatus and SysTinyGetFPCHeapStatus functions
git-svn-id: trunk@33681 -
This commit is contained in:
parent
4af209ac50
commit
91595447c6
@ -60,6 +60,8 @@
|
|||||||
|
|
||||||
TinyHeapAllocGranularity = sizeof(TTinyHeapBlock);
|
TinyHeapAllocGranularity = sizeof(TTinyHeapBlock);
|
||||||
|
|
||||||
|
procedure RegisterTinyHeapBlock(AAddress: pointer; ASize: ptruint); forward;
|
||||||
|
|
||||||
function EncodeTinyHeapFreeBlockSize(Size: PtrUInt): TTinyHeapFreeBlockSize; inline;
|
function EncodeTinyHeapFreeBlockSize(Size: PtrUInt): TTinyHeapFreeBlockSize; inline;
|
||||||
begin
|
begin
|
||||||
{$ifdef FPC_TINYHEAP_HUGE}
|
{$ifdef FPC_TINYHEAP_HUGE}
|
||||||
@ -140,11 +142,33 @@
|
|||||||
begin
|
begin
|
||||||
{ p=HeapPtr }
|
{ p=HeapPtr }
|
||||||
if PtrUInt(TTinyHeapPointerArithmeticType(HeapEnd)-TTinyHeapPointerArithmeticType(HeapPtr))<AllocSize then
|
if PtrUInt(TTinyHeapPointerArithmeticType(HeapEnd)-TTinyHeapPointerArithmeticType(HeapPtr))<AllocSize then
|
||||||
|
begin
|
||||||
|
{ align to 16 bytes }
|
||||||
|
AllocSize:= (AllocSize + $f) and (not $f);
|
||||||
|
p:=SysOSAlloc(AllocSize);
|
||||||
|
if assigned(p) then
|
||||||
|
begin
|
||||||
|
if p > HeapPtr then
|
||||||
|
begin
|
||||||
|
prev:=HeapPtr;
|
||||||
|
HeapPtr:=p;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
RegisterTinyHeapBlock(p,AllocSize);
|
||||||
|
{ Recursive call }
|
||||||
|
SysTinyGetmem:=SysTinyGetmem(Size);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
if ReturnNilIfGrowHeapFails then
|
if ReturnNilIfGrowHeapFails then
|
||||||
Result := nil
|
Result := nil
|
||||||
else
|
else
|
||||||
HandleError(203);
|
HandleError(203);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
result := @PTinyHeapMemBlockSize(HeapPtr)[1];
|
result := @PTinyHeapMemBlockSize(HeapPtr)[1];
|
||||||
PTinyHeapMemBlockSize(HeapPtr)^ := size;
|
PTinyHeapMemBlockSize(HeapPtr)^ := size;
|
||||||
|
|
||||||
@ -250,6 +274,11 @@
|
|||||||
result := findsize(p);
|
result := findsize(p);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function SysTinyTryResizeMem(var p: pointer; size: ptruint) : boolean;
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
function SysTinyAllocMem(size: ptruint): pointer;
|
function SysTinyAllocMem(size: ptruint): pointer;
|
||||||
begin
|
begin
|
||||||
result := SysTinyGetMem(size);
|
result := SysTinyGetMem(size);
|
||||||
@ -486,6 +515,7 @@
|
|||||||
Writeln('RegisterTinyHeapBlock_Simple(', HexStr(AAddress), ',', ASize, ')');
|
Writeln('RegisterTinyHeapBlock_Simple(', HexStr(AAddress), ',', ASize, ')');
|
||||||
{$endif DEBUG_TINY_HEAP}
|
{$endif DEBUG_TINY_HEAP}
|
||||||
InternalTinyAlign(AAddress, ASize);
|
InternalTinyAlign(AAddress, ASize);
|
||||||
|
HeapSize:=HeapSize + ASize;
|
||||||
HeapOrg:=AAddress;
|
HeapOrg:=AAddress;
|
||||||
HeapPtr:=AAddress;
|
HeapPtr:=AAddress;
|
||||||
FreeList:=AAddress;
|
FreeList:=AAddress;
|
||||||
@ -503,6 +533,7 @@
|
|||||||
HeapOrg:=AAddress;
|
HeapOrg:=AAddress;
|
||||||
HeapPtr:=AAddress;
|
HeapPtr:=AAddress;
|
||||||
FreeList:=AAddress;
|
FreeList:=AAddress;
|
||||||
|
HeapSize:=HeapSize + ASize;
|
||||||
HeapEnd:=Pointer(TTinyHeapPointerArithmeticType(AAddress)+ASize);
|
HeapEnd:=Pointer(TTinyHeapPointerArithmeticType(AAddress)+ASize);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -515,6 +546,7 @@
|
|||||||
Writeln('RegisterTinyHeapBlock(', HexStr(AAddress), ',', ASize, ')');
|
Writeln('RegisterTinyHeapBlock(', HexStr(AAddress), ',', ASize, ')');
|
||||||
{$endif DEBUG_TINY_HEAP}
|
{$endif DEBUG_TINY_HEAP}
|
||||||
InternalTinyAlign(AAddress, ASize);
|
InternalTinyAlign(AAddress, ASize);
|
||||||
|
HeapSize:=HeapSize + ASize;
|
||||||
if HeapOrg=nil then
|
if HeapOrg=nil then
|
||||||
begin
|
begin
|
||||||
HeapOrg:=AAddress;
|
HeapOrg:=AAddress;
|
||||||
@ -555,6 +587,48 @@
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function SysTinyGetFPCHeapStatus : TFPCHeapStatus;
|
||||||
|
{
|
||||||
|
TFPCHeapStatus = record
|
||||||
|
|
||||||
|
MaxHeapSize,
|
||||||
|
MaxHeapUsed,
|
||||||
|
CurrHeapSize,
|
||||||
|
CurrHeapUsed,
|
||||||
|
CurrHeapFree : ptruint;
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
begin
|
||||||
|
SysTinyGetFPCHeapStatus.MaxHeapSize:=MaxAvail;
|
||||||
|
{ How can we compute this? }
|
||||||
|
SysTinyGetFPCHeapStatus.MaxHeapUsed:=0;
|
||||||
|
SysTinyGetFPCHeapStatus.CurrHeapFree:=MemAvail;
|
||||||
|
SysTinyGetFPCHeapStatus.CurrHeapUsed:=HeapSize-SysTinyGetFPCHeapStatus.CurrHeapFree;
|
||||||
|
SysTinyGetFPCHeapStatus.CurrHeapSize:=HeapSize;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function SysTinyGetHeapStatus : THeapStatus;
|
||||||
|
begin
|
||||||
|
SysTinyGetHeapStatus.TotalAddrSpace:= HeapSize;
|
||||||
|
SysTinyGetHeapStatus.TotalUncommitted:= 0;
|
||||||
|
SysTinyGetHeapStatus.TotalCommitted:= 0;
|
||||||
|
SysTinyGetHeapStatus.TotalAllocated:= HeapSize-MemAvail;
|
||||||
|
SysTinyGetHeapStatus.TotalFree:= MemAvail;
|
||||||
|
SysTinyGetHeapStatus.FreeSmall:= 0;
|
||||||
|
SysTinyGetHeapStatus.FreeBig:= 0;
|
||||||
|
SysTinyGetHeapStatus.Unused:= 0;
|
||||||
|
SysTinyGetHeapStatus.Overhead:= 0;
|
||||||
|
SysTinyGetHeapStatus.HeapErrorCode:= 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$ifdef FPC_NO_DEFAULT_MEMORYMANAGER}
|
||||||
|
procedure FinalizeHeap;
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$endif FPC_NO_DEFAULT_MEMORYMANAGER}
|
||||||
|
|
||||||
const
|
const
|
||||||
TinyHeapMemoryManager: TMemoryManager = (
|
TinyHeapMemoryManager: TMemoryManager = (
|
||||||
NeedLock: false; // Obsolete
|
NeedLock: false; // Obsolete
|
||||||
@ -567,7 +641,7 @@
|
|||||||
InitThread: nil;
|
InitThread: nil;
|
||||||
DoneThread: nil;
|
DoneThread: nil;
|
||||||
RelocateHeap: nil;
|
RelocateHeap: nil;
|
||||||
GetHeapStatus: nil;
|
GetHeapStatus: @SysTinyGetHeapStatus;
|
||||||
GetFPCHeapStatus: nil;
|
GetFPCHeapStatus: @SysTinyGetFPCHeapStatus;
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user