Bladeren bron

* New heapmanager that releases memory back to the OS, donated
by Micha Nelissen

peter 21 jaren geleden
bovenliggende
commit
2ed14823c5
13 gewijzigde bestanden met toevoegingen van 667 en 366 verwijderingen
  1. 14 1
      rtl/beos/system.pp
  2. 22 1
      rtl/bsd/system.pp
  3. 21 1
      rtl/go32v2/system.pp
  4. 444 346
      rtl/inc/heap.inc
  5. 11 2
      rtl/inc/heaph.inc
  6. 5 5
      rtl/inc/heaptrc.pp
  7. 21 1
      rtl/linux/system.pp
  8. 21 1
      rtl/macos/system.pp
  9. 21 1
      rtl/morphos/system.pp
  10. 21 1
      rtl/netware/system.pp
  11. 23 1
      rtl/template/system.pp
  12. 21 1
      rtl/watcom/system.pp
  13. 22 4
      rtl/win32/system.pp

+ 14 - 1
rtl/beos/system.pp

@@ -176,6 +176,15 @@ begin
   Sbrk:=nil;
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
 
 { include standard heap management }
 {$I heap.inc}
@@ -541,7 +550,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.12  2004-04-22 21:10:56  peter
+  Revision 1.13  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.12  2004/04/22 21:10:56  peter
     * do_read/do_write addr argument changed to pointer
 
   Revision 1.11  2004/01/20 23:09:14  hajny

+ 22 - 1
rtl/bsd/system.pp

@@ -108,6 +108,23 @@ end;
 { OS independant parts}
 
 {$I system.inc}
+
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 { OS dependant parts  }
 
 {$I errno.inc}
@@ -185,7 +202,11 @@ End.
 
 {
   $Log$
-  Revision 1.14  2004-01-22 13:46:14  marco
+  Revision 1.15  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.14  2004/01/22 13:46:14  marco
   bsd
 
   Revision 1.13  2004/01/20 23:09:14  hajny

+ 21 - 1
rtl/go32v2/system.pp

@@ -931,6 +931,22 @@ asm
 {$endif}
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 
 { include standard heap management }
 {$I heap.inc}
@@ -1607,7 +1623,11 @@ Begin
 End.
 {
   $Log$
-  Revision 1.35  2004-05-16 18:51:20  peter
+  Revision 1.36  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.35  2004/05/16 18:51:20  peter
     * use thandle in do_*
 
   Revision 1.34  2004/04/22 21:10:56  peter

File diff suppressed because it is too large
+ 444 - 346
rtl/inc/heap.inc


+ 11 - 2
rtl/inc/heaph.inc

@@ -42,11 +42,16 @@ procedure SetMemoryMutexManager(var MutexMgr: TMemoryMutexManager);
 
 { Variables }
 const
+  growheapsizesmall : ptrint=32*1024; { fixed-size small blocks will grow with 32k }
   growheapsize1 : ptrint=256*1024;  { < 256k will grow with 256k }
   growheapsize2 : ptrint=1024*1024; { > 256k will grow with 1m }
   ReturnNilIfGrowHeapFails : boolean = false;
+
+{ the following variable is needed for heaptrc/win32 }
+{$ifdef WIN32}  
 var
-  heaporg,heapptr,heapend,heaperror,freelist : pointer;
+  HeapOrg: pointer;
+{$endif}  
 
 { Default MemoryManager functions }
 Function  SysGetmem(Size:ptrint):Pointer;
@@ -95,7 +100,11 @@ Procedure AsmFreemem(var p:pointer);
 
 {
   $Log$
-  Revision 1.8  2004-03-15 21:48:26  peter
+  Revision 1.9  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.8  2004/03/15 21:48:26  peter
     * cmem moved to rtl
     * longint replaced with ptrint in heapmanagers
 

+ 5 - 5
rtl/inc/heaptrc.pp

@@ -721,7 +721,6 @@ var
 
 {$ifdef win32}
 var
-   StartUpHeapEnd : pointer;
    { I found no symbol for start of text section :(
      so we usee the _mainCRTStartup which should be
      in wprt0.ow or wdllprt0.ow PM }
@@ -1019,9 +1018,6 @@ begin
 {$ifdef go32v2}
   Heap_at_init:=HeapPtr;
 {$endif}
-{$ifdef win32}
-  StartupHeapEnd:=HeapEnd;
-{$endif}
 end;
 
 
@@ -1156,7 +1152,11 @@ finalization
 end.
 {
   $Log$
-  Revision 1.29  2004-05-22 20:35:52  peter
+  Revision 1.30  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.29  2004/05/22 20:35:52  peter
   check whether bp is in the stack value allocated by the main program
 
   Revision 1.28  2004/04/28 20:48:20  peter

+ 21 - 1
rtl/linux/system.pp

@@ -101,6 +101,22 @@ function fpgetcwd(buf:pchar;_size:size_t):pchar; cdecl; external name 'getcwd';
 {$I ossysc.inc}                         // base syscalls
 {$I osmain.inc}                         // base wrappers *nix RTL (derivatives)
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 { more OS independant parts}
 
 {$I text.inc}
@@ -174,7 +190,11 @@ End.
 
 {
   $Log$
-  Revision 1.14  2004-01-20 23:09:14  hajny
+  Revision 1.15  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.14  2004/01/20 23:09:14  hajny
     * ExecuteProcess fixes, ProcessID and ThreadID added
 
   Revision 1.13  2004/01/01 14:16:55  marco

+ 21 - 1
rtl/macos/system.pp

@@ -641,6 +641,22 @@ end;
 function Sbrk(logicalSize: Longint): Mac_Ptr ;
 external 'InterfaceLib' name 'NewPtr'; {Directly mapped to NewPtr}
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 
 { include standard heap management }
 {$I heap.inc}
@@ -1168,7 +1184,11 @@ end.
 
 {
   $Log$
-  Revision 1.15  2004-05-11 18:05:41  olle
+  Revision 1.16  2004-06-17 16:16:13  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.15  2004/05/11 18:05:41  olle
     + added call to MaxApplZone to have the whole MacOS heap available
 
   Revision 1.14  2004/04/29 11:27:36  olle

+ 21 - 1
rtl/morphos/system.pp

@@ -716,6 +716,22 @@ begin
   Sbrk:=AllocPooled(MOS_heapPool,size);
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 {$I heap.inc}
 
 
@@ -1162,7 +1178,11 @@ end.
 
 {
   $Log$
-  Revision 1.13  2004-06-13 22:50:47  karoly
+  Revision 1.14  2004-06-17 16:16:14  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.13  2004/06/13 22:50:47  karoly
     * cleanup and changes to use new includes
 
   Revision 1.12  2004/06/06 23:31:13  karoly

+ 21 - 1
rtl/netware/system.pp

@@ -307,6 +307,22 @@ begin
   end;
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 { include standard heap management }
 {$I heap.inc}
 
@@ -819,7 +835,11 @@ Begin
 End.
 {
   $Log$
-  Revision 1.21  2004-01-20 23:11:20  hajny
+  Revision 1.22  2004-06-17 16:16:14  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.21  2004/01/20 23:11:20  hajny
     * ExecuteProcess fixes, ProcessID and ThreadID added
 
   Revision 1.20  2003/10/25 23:43:59  hajny

+ 23 - 1
rtl/template/system.pp

@@ -143,6 +143,24 @@ begin
   Sbrk:=nil;
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+// If the OS is capable of freeing memory, define HAS_SYSOSFREE and implement
+// the SysOSFree function properly
+//{$define HAS_SYSOSFREE}
+{
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  // code to release memory block
+end;
+}
 
 { include standard heap management }
 {$I heap.inc}
@@ -298,7 +316,11 @@ Begin
 End.
 {
   $Log$
-  Revision 1.10  2004-01-20 23:12:49  hajny
+  Revision 1.11  2004-06-17 16:16:14  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.10  2004/01/20 23:12:49  hajny
     * ExecuteProcess fixes, ProcessID and ThreadID added
 
   Revision 1.9  2003/09/27 11:52:36  peter

+ 21 - 1
rtl/watcom/system.pp

@@ -864,6 +864,22 @@ asm
 {$endif}
 end;
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
+
+function SysOSAlloc(size: ptrint): pointer;
+begin
+  result := sbrk(size);
+end;
+
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  fpmunmap(p, size);
+end;
+
 { include standard heap management }
 {$include heap.inc}
 
@@ -1537,7 +1553,11 @@ End.
 
 {
   $Log$
-  Revision 1.13  2004-04-22 21:10:56  peter
+  Revision 1.14  2004-06-17 16:16:14  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.13  2004/04/22 21:10:56  peter
     * do_read/do_write addr argument changed to pointer
 
   Revision 1.12  2004/01/20 23:12:49  hajny

+ 22 - 4
rtl/win32/system.pp

@@ -257,6 +257,8 @@ end;
      stdcall;external 'kernel32' name 'GetProcessHeap';
    function HeapAlloc(hHeap : DWord; dwFlags : DWord; dwBytes : DWord) : Longint;
      stdcall;external 'kernel32' name 'HeapAlloc';
+   function HeapFree(hHeap : dword; dwFlags : dword; lpMem: pointer) : boolean;
+     stdcall;external 'kernel32' name 'HeapFree';
 {$IFDEF SYSTEMDEBUG}
    function WinAPIHeapSize(hHeap : DWord; dwFlags : DWord; ptr : Pointer) : DWord;
      stdcall;external 'kernel32' name 'HeapSize';
@@ -279,18 +281,29 @@ asm
         movl    intern_HEAPSIZE,%eax
 end ['EAX'];
 
+{*****************************************************************************
+      OS Memory allocation / deallocation 
+ ****************************************************************************}
 
-function Sbrk(size : longint):pointer;
+function SysOSAlloc(size: ptrint): pointer;
 var
   l : longword;
 begin
-  l := HeapAlloc(GetProcessHeap(), 0, size);
+  l := HeapAlloc(GetProcessHeap, 0, size);
 {$ifdef DUMPGROW}
   Writeln('new heap part at $',hexstr(l,8), ' size = ',WinAPIHeapSize(GetProcessHeap()));
 {$endif}
-  sbrk:=pointer(l);
+  SysOSAlloc := pointer(l);
 end;
 
+{$define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptrint);
+begin
+  HeapFree(GetProcessHeap, 0, p);
+end;
+
+
 { include standard heap management }
 {$I heap.inc}
 
@@ -1590,6 +1603,7 @@ begin
   MainInstance:=HInstance;
   cmdshow:=startupinfo.wshowwindow;
   { Setup heap }
+  HeapOrg:=GetHeapStart;
   InitHeap;
   SysInitExceptions;
   SysInitStdIO;
@@ -1608,7 +1622,11 @@ end.
 
 {
   $Log$
-  Revision 1.56  2004-05-16 18:51:20  peter
+  Revision 1.57  2004-06-17 16:16:14  peter
+    * New heapmanager that releases memory back to the OS, donated
+      by Micha Nelissen
+
+  Revision 1.56  2004/05/16 18:51:20  peter
     * use thandle in do_*
 
   Revision 1.55  2004/04/22 21:10:56  peter

Some files were not shown because too many files changed in this diff