2013年3月23日

c++ placement new的标准用法及用途

摘要: 原文地址:http://blog.csdn.net/lazyking/article/details/5319580什么是placement new?所谓placement new就是在用户指定的内存位置上构建新的对象,这个构建过程不需要额外分配内存,只需要调用对象的构造函数即可。举例来说:class foo{};foo* pfoo = new foo;pfoo指向的对象的地址是不能决定的,因为new已经为我们做了这些工作:第一步分配内存,第二步调用类的构造函数。而placement new是怎么做的呢,说白了就是把原本new做的两步工作分开来。第一步你自己分配内存,第二步你调用类的构造函数在 阅读全文

posted @ 2013-03-23 10:58 zhuyf87 阅读(1041) 评论(0) 推荐(0) 编辑

c++ new的三种形态

摘要: (1)new operatornew的第一种形态是new operator,它是语言内建的,不能重载。new operator完成以下三件工作:1. allocate memory for this object.2. call constructor to init that memory.3. return the pointer of this object.例如:string *pStr = new string(“Memory Management”);它实际完成以下三件事:// 1. 为string对象分配raw内存void *memroy = operator new( size 阅读全文

posted @ 2013-03-23 10:20 zhuyf87 阅读(1126) 评论(0) 推荐(2) 编辑

导航