从反汇编看待C++ new

首先来看最简单的new操作
  1. int main()
  2. {
  3. int *temp = new int;
  4. delete temp;
  5. }
反汇编结果:调用了operator new
  1. 00311C9E push 4
  2. 00311CA0 call operator new (0311438h)
  3. 00311CA5 add esp,4
进入operator new中查看
  1. void* __CRTDECL operator new(size_t const size)
  2. {
  3. 00315320 push ebp
  4. 00315321 mov ebp,esp
  5. 00315323 push ecx
  6. for (;;)
  7. {
  8. if (void* const block = malloc(size))
  9. 00315324 mov eax,dword ptr [size]
  10. 00315327 push eax
  11. 00315328 call _malloc (03111B3h)
  12. 0031532D add esp,4
  13. 00315330 mov dword ptr [ebp-4],eax
  14. 00315333 cmp dword ptr [ebp-4],0
  15. 00315337 je operator new+1Eh (031533Eh)
  16. return block;
  17. 省略..................
发现其底层也调用了malloc函数



posted on 2016-07-17 18:51  笨拙的菜鸟  阅读(593)  评论(0编辑  收藏  举报

导航