SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
can::NewArray< T > Class Template Reference

wrapper over operator new/delete [] More...

Inheritance diagram for can::NewArray< T >:
can::Array< T, 0 >

Public Member Functions

 NewArray ()
 default initialize pointer to zero
 
 NewArray (std::size_t n)
 construct with (n) elements
 
 ~NewArray ()
 Array destructor frees memory.
 
bool allocated () const
 return true if memory has been allocated
 
void deallocate ()
 user-callable deallocation helper
 
void allocate (std::size_t n)
 user-callable allocation helper More...
 
- Public Member Functions inherited from can::Array< T, 0 >
 Array ()
 default constructor - no allocation
 
 Array (unsigned n)
 construct with n elems
 
 Array (Array< T, 0 > const &other)
 copy constructor
 
 ~Array ()
 destructor - need to delete elems
 
Array< T, 0 > & operator= (Array< T, 0 > const &other)
 assignment operator
 
T & operator[] (unsigned i)
 mutable index operator
 
T const & operator[] (unsigned i) const
 immutable index operator
 
unsigned size () const
 get the size of this array
 
void resize (unsigned n)
 resize the array
 

Detailed Description

template<class T>
class can::NewArray< T >

wrapper over operator new/delete []

this wrapper is used to automatically call delete [] on an array created with new [], preventing memory leaks and forming the base class for other containers. Ideally, all usage of operator new [] should be replaced with this.

Definition at line 27 of file canNewArray.h.

Member Function Documentation

template<class T>
void can::NewArray< T >::allocate ( std::size_t  n)
inline

user-callable allocation helper

note that no mix of allocate/deallocate calls can cause a memory leak

Definition at line 48 of file canNewArray.h.

48 {this->resize(n);}
void resize(unsigned n)
resize the array
Definition: canArray.h:80

The documentation for this class was generated from the following file: