1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

*Similarly,
T* ta = new T[n];

T* ta = (T*) malloc (n * sizeof(T));

are equivalent, except that the default constructor for T,
T :: T()
is called n times, if it exists

*

the size of the resulting array is saved "somewhere'' for use by delete[]

ta = new T[0];
also returns a pointer to an object of type T

*

*

when no storage is available, new returns NULL, so a quick and dirty way of checking is:

ta = new T[n];assert( ta ); assert( ta = new T[n] );

delete vs. free()
delete tp; is equivalent to free(tp);

//or even

*

delete[] tp;
is not defined if tp is not allocated with the array syntax

*

deleting parts of arrays or other proper subsets of the memory returned by new is not defined

16-Mar-98

Page 13

C201/TAM/AGS