⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sharememrep.pas

📁 delphi开发语言下的源代码分析
💻 PAS
字号:
(*
  ShareMemRep Version: 1.1
  =========================
   - Aimingoo (aim@263.net)
   - 2003.08.05
   - Free and OpenSource
*)

unit ShareMemRep;

interface

{ Same define in ShareMem.pas for Delphi }
var
  GetHeapStatus: function: THeapStatus;
  GetAllocMemCount: function: Integer;
  GetAllocMemSize: function: Integer;

implementation

uses
  Windows;

const
  Err_ReplaceFailed = 'Shared Memory Replace failed!'#$0D#$0A#$0D#$0A +
                      '  - Host App must uses ShareMemRep.pas!'#$0D#$0A +
                      '  - ShareMemRep.pas nust is first of uses list!';
var
  ExeName: array [0..255] of char;
  hExe: HModule;
  OldMemMgr: TMemoryManager;
  MemMgr: TMemoryManager;
  _GetMemoryManager: procedure (var MemMgr: TMemoryManager);

function _GetAllocMemCount: Integer;
begin
  Result := System.AllocMemCount;
end;

function _GetAllocMemSize: Integer;
begin
  Result := System.AllocMemSize;
end;

exports
  System.GetMemoryManager,
  System.GetHeapStatus,
  _GetAllocMemCount name 'GetAllocMemCount',   { Number of allocated memory blocks } 
  _GetAllocMemSize name 'GetAllocMemSize';     { Total size of allocated memory blocks }


initialization
  if IsLibrary then
  begin
    GetModuleFileName(0, @ExeName, 255);
    hExe := GetModuleHandle(@ExeName);
    _GetMemoryManager := GetProcAddress(hExe, 'GetMemoryManager');
    if (System.AllocMemSize<>0) or (hExe = 0) or (@_GetMemoryManager = nil) then
    begin
      MessageBox(0, Err_ReplaceFailed, 'ShareMemRep 1.0', 0);
      TerminateProcess(GetCurrentProcess, 0);
    end;
    GetHeapStatus := GetProcAddress(hExe, 'GetHeapStatus');
    GetAllocMemCount := GetProcAddress(hExe, 'GetAllocMemCount');
    GetAllocMemSize := GetProcAddress(hExe, 'GetAllocMemSize');

    _GetMemoryManager(MemMgr);
    GetMemoryManager(OldMemMgr);
    SetMemoryManager(MemMgr);
  end
  else
  begin
    GetHeapStatus := System.GetHeapStatus;
    GetAllocMemCount := _GetAllocMemCount;
    GetAllocMemSize := _GetAllocMemSize;
  end;


finalization
  if IsLibrary then
    SetMemoryManager(OldMemMgr);

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -