Browse Source

+ added and implemented MemAvail and MaxAvail for the tiny heap

git-svn-id: trunk@28664 -
nickysn 11 years ago
parent
commit
624b3204d8
2 changed files with 37 additions and 0 deletions
  1. 34 0
      rtl/inc/tinyheap.inc
  2. 3 0
      rtl/inc/tnyheaph.inc

+ 34 - 0
rtl/inc/tinyheap.inc

@@ -291,6 +291,40 @@
 {$endif DEBUG_TINY_HEAP}
       end;
 
+    function MemAvail: PtrUInt;
+      var
+        p: PTinyHeapBlock;
+      begin
+        MemAvail := PtrUInt(TTinyHeapPointerArithmeticType(HeapEnd)-TTinyHeapPointerArithmeticType(HeapPtr));
+        if MemAvail > 0 then
+          Dec(MemAvail, SizeOf(TTinyHeapMemBlockSize));
+
+        p := FreeList;
+        while p <> HeapPtr do
+          begin
+            Inc(MemAvail, DecodeTinyHeapFreeBlockSize(p^.Size)-SizeOf(TTinyHeapMemBlockSize));
+            p := p^.Next;
+          end;
+      end;
+
+    function MaxAvail: PtrUInt;
+      var
+        p: PTinyHeapBlock;
+      begin
+        MaxAvail := PtrUInt(TTinyHeapPointerArithmeticType(HeapEnd)-TTinyHeapPointerArithmeticType(HeapPtr));
+
+        p := FreeList;
+        while p <> HeapPtr do
+          begin
+            if DecodeTinyHeapFreeBlockSize(p^.Size) > MaxAvail then
+              MaxAvail := DecodeTinyHeapFreeBlockSize(p^.Size);
+            p := p^.Next;
+          end;
+
+        if MaxAvail > 0 then
+          Dec(MaxAvail, SizeOf(TTinyHeapMemBlockSize));
+      end;
+
     procedure InternalTinyAlign(var AAddress: Pointer; ASize: PtrUInt);
       var
         alignment_inc: smallint;

+ 3 - 0
rtl/inc/tnyheaph.inc

@@ -20,3 +20,6 @@
       FreeList: Pointer = nil; { pointer to the first free block }
       HeapPtr: Pointer = nil;  { pointer to the last free block }
 
+    function MemAvail: PtrUInt;
+    function MaxAvail: PtrUInt;
+