delphi 自定义内存管理

1.主要通过GetMemoryManager来hook原来的内存管理。

2.通过SetMemoryManager来设置你自己的新的内存管理,可以用一个内存池来优化和管理程序的内存调用情况。

procedure RegisterMemMgr;
var
  AMgr: TMemoryManagerEx;
begin
GetMemoryManager(OldMemMgr);
AMgr.GetMem := Hook_GetMem;
AMgr.FreeMem := Hook_FreeMem;
AMgr.ReallocMem := Hook_ReallocMem;
AMgr.AllocMem := Hook_AllocMem;
AMgr.RegisterExpectedMemoryLeak := Hook_RegisterExpectedMemoryLeak;
AMgr.UnregisterExpectedMemoryLeak := Hook_UnregisterExpectedMemoryLeak;
SetMemoryManager(AMgr);
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi 中少见的第三方内存管理器,QStrings 的作者 Andrew Driazgov 发布 QMemory is a new memory manager. You can use it as a replacement of the default system memory manager. To do this simply add QMemory unit in your project (as the first unit listed in the project file). Don‘t forget to call the QMemDecommitOverstock function when your application is idle. This subroutine decommits the unused memory blocks (it‘s only way for program to return the memory to the operation system). All allocated memory blocks are 32 byte aligned. The minimum size of the block is 32 bytes. As it is necessary to store some information with each block a dword is attached to the front of each block at -4 the aligned address. Thus, memory request for up to 28 bytes allocates a 32-bytes block, request for 29 to 60 bytes allocates a 64-bytes block, etc (as power of 2). This idea was adopted from HPMM project of Robert Lee (rhlee@optimalcode.com). The memory is committed and decommitted in 64K blocks. The maximum amount of the memory is specified when QMemInstall function is called (from the initialization section of the unit). You can‘t change this value later. If some parts of your program implemented as DLLs you have to use ShareQmm instead of QMemory unit. ShareQmm must be the first unit in your library‘s USES clause AND your project‘s (select Project-View Source) USES clause if some parts of your program have done as separate DLLs (especially if they export any procedures or functions that pass strings as parameters or function results). ShareQmm is the interface unit to the QMM.DLL shared memory manager, which must be deployed along with your DLL. You can‘t combine using of the standard ShareMem and custom ShareQmm memory managers in the same program project (including EXE-file with all DLLs). You can use either ShareMem or ShareQmm, but not both together. ShareQmm memory manager works at the same speed as a ShareMem memory manager with the blocks up to 4096 bytes and much more faster with the larger blocks.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值