home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / Runimage / Delphi50 / Source / Rtl / Sys / sharemem.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  2.3 KB  |  117 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Runtime Library                  }
  5. {                                                       }
  6. {       Copyright (C) 1995,99 Inprise Corporation       }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit ShareMem;
  11.  
  12. interface
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. function SysGetMem(Size: Integer): Pointer;
  20. function SysFreeMem(P: Pointer): Integer;
  21. function SysReallocMem(P: Pointer; Size: Integer): Pointer;
  22. function GetHeapStatus: THeapStatus;
  23. function GetAllocMemCount: Integer;
  24. function GetAllocMemSize: Integer;
  25. procedure DumpBlocks;
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. implementation
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. const
  49.   DelphiMM = 'borlndmm.dll';
  50.  
  51. function SysGetMem(Size: Integer): Pointer; external DelphiMM name '@Borlndmm@SysGetMem$qqri';
  52. function SysFreeMem(P: Pointer): Integer; external DelphiMM name '@Borlndmm@SysFreeMem$qqrpv';
  53. function SysReallocMem(P: Pointer; Size: Integer): Pointer; external DelphiMM name '@Borlndmm@SysReallocMem$qqrpvi';
  54. function GetHeapStatus: THeapStatus; external DelphiMM;
  55. function GetAllocMemCount: Integer; external DelphiMM;
  56. function GetAllocMemSize: Integer; external DelphiMM;
  57. procedure DumpBlocks; external DelphiMM;
  58.  
  59. function GetModuleHandle(lpModuleName: PChar): Integer; stdcall;
  60.   external 'kernel32.dll' name 'GetModuleHandleA';
  61. function GetProcAddress(hModule: Integer; lpProcName: PChar): Pointer; stdcall;
  62.   external 'kernel32.dll' name 'GetProcAddress';
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. procedure InitMemoryManager;
  103. var
  104.   SharedMemoryManager: TMemoryManager;
  105.   MM: Integer;
  106. begin
  107.   // force a static reference to borlndmm.dll, so we don't have to LoadLibrary
  108.   SharedMemoryManager.GetMem := SysGetMem;
  109.  
  110.   MM := GetModuleHandle(DelphiMM);
  111.   SharedMemoryManager.GetMem := GetProcAddress(MM,'@Borlndmm@SysGetMem$qqri');
  112.   SharedMemoryManager.FreeMem := GetProcAddress(MM,'@Borlndmm@SysFreeMem$qqrpv');
  113.   SharedMemoryManager.ReallocMem := GetProcAddress(MM, '@Borlndmm@SysReallocMem$qqrpvi');
  114.   SetMemoryManager(SharedMemoryManager);
  115. end;
  116.  
  117. initialization
  118.   if not IsMemoryManagerSet then
  119.     InitMemoryManager;
  120. end.
  121.