1.简介
scoped_array很像scoped_ptr,它包装了new[ ]操作符(不是单纯的new)在堆上分配的动态数组,为动态数组提供了一个代理,包装可以正确地释放内存。
2. scoped_array 分析
scoped_array 的类摘要如下所示(这里列出重要部分):
template<class T> class scoped_array // noncopyable
{
private:
T * px;
scoped_array(scoped_array const &);
scoped_array & operator=(scoped_array const &);
typedef scoped_array<T> this_type;
void operator==( scoped_array const& ) const;
void operator!=( scoped_array const& ) const;
public:
typedef T element_type;
explicit scoped_array( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p )
{
}
~scoped_array() // never throws
{
boost::checked_array_delete( px );
}
void reset(T * p = 0) // never throws (but has a BOOST_ASSERT in it, so not marked with BOOST_NOEXCEPT)