这是我在网上逛的时候发现的一个讨论, 起源是< >一书中的一些例子。查了一些资料,把我的结论写在这里。先让我们看一个论述比较好的帖子,e文的,耐心点看。
Mismatching scalar and vector new and delete
In a previous entry I alluded to the problems that can occur if you mismatch scalar "new" with vector "delete[]" or vice versa.
There is a nice description of C++ memory management in C++ Gotchas: Avoiding Common Problems in Coding and Design on www.informit.com, and I encourage you to read at least the section titled Failure to Distinguish Scalar and Array Allocation before continuing with this entry, because I'm going to use that information as a starting point.
Here's how the Microsoft C++ compiler manages vector allocation. Note that this is internal implementation detail, so it's subject to change at any time, but