注册 登录
编程论坛 C++教室

关于operator new

specilize 发布于 2011-06-28 17:23, 371 次点击
假设我要分配50个int对象,那我可以这样写
void* buffer operator new(50*sizeof(int));
也可以这样写
void* buffer operator new[](50*sizeof(int));
这两种方法除了delete时应使用相应的形式外,到底有什么其他的不同的
1 回复
#2
rjsp2011-06-29 08:46
目前看来无不同,但我帮你google了一下

Why are operator new and operator new[] different? One often wants to implement a simple new/delete for a particular class (for instance by keeping a freelist) while not worrying about cases where one must allocate different-sized chunks of memory. Defining operators new and delete for a class but not new[] and delete[] accomplishes exactly this.
http://www.scs.stanford.edu/~dm/home/papers/c++-new.html
1