您的位置:首页 > 编程语言

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

2012-01-29 19:00 337 查看
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.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息