滴水逆向——C++_new/delete、vector

1、new/delete

1.跟踪反汇编,查看函数的封装:

   malloc    _nh_malloc_dbg            _heap_alloc_dbg        _heap_alloc_base        HeapAlloc
   new        _nh_malloc                    _nh_malloc_dbg         _heap_alloc_dbg        _heap_alloc_base        HeapAlloc

   free         _free_dbg                      _free_base                 HeapFree
   delete     _free_dbg 

2.new 关键字
   int* pi = new int;
   int* pk = new int(5);
   Person* ps = new Person;
   Person* pd = new Person(1, 2);

   第一步:_nh_malloc->_nh_malloc_dbg->_heap_alloc_dbg->_heap_alloc_base->HeapAlloc
   第二步:调用构造函数

3.delete关键字
   delete pi;
   delete pk;

   第一步:调用析构函数
   第二步:_free_dbg->_free_base->HeapFree

4.new[] 与 delete[]的用法.
   int* pi = new int[10];
   delete[] pi;

   Person* p = new Person[2];
   delete[] p;

2、vector

#include<stdio.h>
#include<Windows.h>

#define SUCCESS           			 1 // 成功								
#define ERROR            			 -1 // 失败								
#define MALLOC_ERROR			 -2 // 申请内存失败								
#define INDEX_ERROR		 	 -3 // 错误的索引号								

template <class T_ELE>
class Vector
{
public:
	Vector();
	Vector(DWORD dwSize);
	~Vector();
public:
	DWORD	at(DWORD dwIndex, OUT T_ELE* pEle);					//根据给定的索引得到元素				
	DWORD    push_back(T_ELE Element);						//将元素存储到容器最后一个位置				
	VOID	pop_back();			
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值