通用编程能力训练:Memory Track(2012-01-29 19:02)

Basic Steps:

1, Replace new/delete by HeapAlloc/HeapFree;

2, Statistic when allocate and free the memory, special the CallStack when the allocate function has been called;

3, Dump all the non-free allocate calls;

 

Details:

 What are new and operator new and how does they working

http://eli.thegreenplace.net/2011/02/17/the-many-faces-of-operator-new-in-c/

 

What dose MSDN say

operator new : http://msdn.microsoft.com/zh-cn/library/we2zys4d(v=VS.100).aspx

operator delete : http://msdn.microsoft.com/zh-cn/library/kwsyy0kw.aspx

 

Replacement memory  management : Buildin Type

allocate and free memory : MT_Alloc / MT_Free;

code here;

 

memory stats : MT_Stats;

code here;

 

Initialize timing

Useage for init_seg, see MSDN :http://msdn.microsoft.com/zh-cn/library/7977wcck(v=VS.71).aspx

If the application is simple , the timing maybe not importent;

 

Replacement memory  management : STL Type, std::vector for example

implament a allocator like class allocator in <xmemory>, include all of the member functions;

code here;

 

remark:

1, stl use count, not size, if you want get the size, like this: _Count * sizeof( _Ty);

2, check the std::bad_alloc before call the custom memory allocate function that likeMT_Alloc,just do what dose std::allocator like.

3, replacement new can NOT handle template expression such as new(ptr)(std::vector<int,Allocator_STL<int>>), because it's include "," . Use typedef keyword before that;

 

What do i do on the Mutli-Thread situcation

 

Other: Memory Management

What are the memory management libraries already exsit?

How to use Ned Library in my solution.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值