Browse Source

+ optimization in SysTinyReAllocMem for the case of shrinking a memory block

git-svn-id: trunk@28714 -
nickysn 11 years ago
parent
commit
e4f3f33692
1 changed files with 6 additions and 0 deletions
  1. 6 0
      rtl/inc/tinyheap.inc

+ 6 - 0
rtl/inc/tinyheap.inc

@@ -288,6 +288,12 @@
                 if size > oldsize then
                 if size > oldsize then
                   FillChar((TTinyHeapPointerArithmeticType(p)+oldsize)^, size-oldsize, 0);
                   FillChar((TTinyHeapPointerArithmeticType(p)+oldsize)^, size-oldsize, 0);
               end
               end
+            else if OldAllocSize > NewAllocSize then
+              begin
+                { we're decreasing the memory block size, so we can just free the remaining memory at the end }
+                PTinyHeapMemBlockSize(p)[-1] := size;
+                InternalTinyFreeMem(Pointer(TTinyHeapPointerArithmeticType(p)+(NewAllocSize-PtrUInt(SizeOf(TTinyHeapMemBlockSize)))), OldAllocSize-NewAllocSize);
+              end
             else
             else
               begin
               begin
                 result := AllocMem(size);
                 result := AllocMem(size);