|
@@ -33,7 +33,14 @@
|
|
|
|
|
|
{ TTinyHeapFreeBlockSize holds the size of a *free* memory block, as a
|
|
{ TTinyHeapFreeBlockSize holds the size of a *free* memory block, as a
|
|
part of the TTinyHeapBlock structure }
|
|
part of the TTinyHeapBlock structure }
|
|
|
|
+{$ifdef FPC_HEAP_HUGE}
|
|
|
|
+ TTinyHeapFreeBlockSize = record
|
|
|
|
+ OfsSize: Word;
|
|
|
|
+ SegSize: Word;
|
|
|
|
+ end;
|
|
|
|
+{$else FPC_HEAP_HUGE}
|
|
TTinyHeapFreeBlockSize = PtrUInt;
|
|
TTinyHeapFreeBlockSize = PtrUInt;
|
|
|
|
+{$endif FPC_HEAP_HUGE}
|
|
|
|
|
|
TTinyHeapPointerArithmeticType = ^Byte; {$ifdef FPC_HEAP_HUGE}huge;{$endif}
|
|
TTinyHeapPointerArithmeticType = ^Byte; {$ifdef FPC_HEAP_HUGE}huge;{$endif}
|
|
|
|
|
|
@@ -51,7 +58,26 @@
|
|
var
|
|
var
|
|
TinyHeapBlocks: PTinyHeapBlock = nil;
|
|
TinyHeapBlocks: PTinyHeapBlock = nil;
|
|
|
|
|
|
- procedure InternalTinyFreeMem(Addr: Pointer; Size: TTinyHeapFreeBlockSize); forward;
|
|
|
|
|
|
+ function EncodeTinyHeapFreeBlockSize(Size: PtrUInt): TTinyHeapFreeBlockSize; inline;
|
|
|
|
+ begin
|
|
|
|
+{$ifdef FPC_HEAP_HUGE}
|
|
|
|
+ EncodeTinyHeapFreeBlockSize.OfsSize := Size and 15;
|
|
|
|
+ EncodeTinyHeapFreeBlockSize.SegSize := Size shr 4;
|
|
|
|
+{$else FPC_HEAP_HUGE}
|
|
|
|
+ EncodeTinyHeapFreeBlockSize := Size;
|
|
|
|
+{$endif FPC_HEAP_HUGE}
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function DecodeTinyHeapFreeBlockSize(Size: TTinyHeapFreeBlockSize): PtrUInt; inline;
|
|
|
|
+ begin
|
|
|
|
+{$ifdef FPC_HEAP_HUGE}
|
|
|
|
+ DecodeTinyHeapFreeBlockSize := (PtrUInt(Size.SegSize) shl 4) + Size.OfsSize;
|
|
|
|
+{$else FPC_HEAP_HUGE}
|
|
|
|
+ DecodeTinyHeapFreeBlockSize := Size;
|
|
|
|
+{$endif FPC_HEAP_HUGE}
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ procedure InternalTinyFreeMem(Addr: Pointer; Size: PtrUInt); forward;
|
|
|
|
|
|
function FindSize(p: pointer): TTinyHeapMemBlockSize;
|
|
function FindSize(p: pointer): TTinyHeapMemBlockSize;
|
|
begin
|
|
begin
|
|
@@ -70,7 +96,7 @@
|
|
|
|
|
|
p := TinyHeapBlocks;
|
|
p := TinyHeapBlocks;
|
|
prev := nil;
|
|
prev := nil;
|
|
- while assigned(p) and (p^.Size < AllocSize) do
|
|
|
|
|
|
+ while assigned(p) and (DecodeTinyHeapFreeBlockSize(p^.Size) < AllocSize) do
|
|
begin
|
|
begin
|
|
prev := p;
|
|
prev := p;
|
|
p := p^.Next;
|
|
p := p^.Next;
|
|
@@ -80,11 +106,11 @@
|
|
begin
|
|
begin
|
|
result := @PTinyHeapMemBlockSize(p)[1];
|
|
result := @PTinyHeapMemBlockSize(p)[1];
|
|
|
|
|
|
- if p^.Size-AllocSize >= TinyHeapMinBlock then
|
|
|
|
- RestSize := p^.Size-AllocSize
|
|
|
|
|
|
+ if DecodeTinyHeapFreeBlockSize(p^.Size)-AllocSize >= TinyHeapMinBlock then
|
|
|
|
+ RestSize := DecodeTinyHeapFreeBlockSize(p^.Size)-AllocSize
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- AllocSize := p^.Size;
|
|
|
|
|
|
+ AllocSize := DecodeTinyHeapFreeBlockSize(p^.Size);
|
|
RestSize := 0;
|
|
RestSize := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -124,7 +150,7 @@
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
- procedure InternalTinyFreeMem(Addr: Pointer; Size: TTinyHeapFreeBlockSize);
|
|
|
|
|
|
+ procedure InternalTinyFreeMem(Addr: Pointer; Size: PtrUInt);
|
|
var
|
|
var
|
|
b, p, prev: PTinyHeapBlock;
|
|
b, p, prev: PTinyHeapBlock;
|
|
EndAddr: Pointer;
|
|
EndAddr: Pointer;
|
|
@@ -135,7 +161,7 @@
|
|
b := addr;
|
|
b := addr;
|
|
|
|
|
|
b^.Next := TinyHeapBlocks;
|
|
b^.Next := TinyHeapBlocks;
|
|
- b^.Size := Size;
|
|
|
|
|
|
+ b^.Size := EncodeTinyHeapFreeBlockSize(Size);
|
|
EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size);
|
|
EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size);
|
|
|
|
|
|
if TinyHeapBlocks = nil then
|
|
if TinyHeapBlocks = nil then
|
|
@@ -147,10 +173,10 @@
|
|
|
|
|
|
while assigned(p) do
|
|
while assigned(p) do
|
|
begin
|
|
begin
|
|
- if (TTinyHeapPointerArithmeticType(p)+p^.Size) = TTinyHeapPointerArithmeticType(Addr) then
|
|
|
|
|
|
+ if (TTinyHeapPointerArithmeticType(p)+DecodeTinyHeapFreeBlockSize(p^.Size)) = TTinyHeapPointerArithmeticType(Addr) then
|
|
begin
|
|
begin
|
|
addr:=p;
|
|
addr:=p;
|
|
- size:=p^.size+size;
|
|
|
|
|
|
+ size:=DecodeTinyHeapFreeBlockSize(p^.size)+size;
|
|
if prev = nil then
|
|
if prev = nil then
|
|
TinyHeapBlocks:=p^.next
|
|
TinyHeapBlocks:=p^.next
|
|
else
|
|
else
|
|
@@ -160,7 +186,7 @@
|
|
end
|
|
end
|
|
else if p = EndAddr then
|
|
else if p = EndAddr then
|
|
begin
|
|
begin
|
|
- size:=p^.size+size;
|
|
|
|
|
|
+ size:=DecodeTinyHeapFreeBlockSize(p^.size)+size;
|
|
if prev = nil then
|
|
if prev = nil then
|
|
TinyHeapBlocks:=p^.next
|
|
TinyHeapBlocks:=p^.next
|
|
else
|
|
else
|