* Set all entries to their
* default value (i.e. copy them
* over with default constructed
- * objects).
+ * objects). Do not change the
+ * size of the table, though.
*/
- void clear ();
+ void reset_values ();
/**
* Set the dimensions of this
template <int N, typename T>
inline
void
-TableBase<N,T>::clear ()
+TableBase<N,T>::reset_values ()
{
if (n_elements() != 0)
std::fill_n (val, n_elements(), T());
table_size = TableIndices<N>();
return;
- };
+ }
// if new size is nonzero:
// if necessary allocate
val_size = new_size;
val = new T[val_size];
- };
+ }
// reinitialize contents of old or
- // new memory.
- clear ();
+ // new memory. note that we
+ // actually need to do this here,
+ // even in the case that we
+ // reallocated memory, since per
+ // C++ standard, clause 5.3.4/15
+ // the newly allocated objects are
+ // only default initialized by
+ // operator new[] if they are
+ // non-POD type. In other words, if
+ // we have a table of doubles, then
+ // their values after calling 'new
+ // double[val_size]' is
+ // indetermined.
+ reset_values ();
}
reinit (const BlockSparsityPattern &sparsity)
{
// first delete previous content of
- // the subobjects array
+ // the subobjects array and delete
+ // the table completely
for (unsigned int r=0; r<rows; ++r)
for (unsigned int c=0; c<columns; ++c)
{
sub_objects[r][c] = 0;
delete p;
}
-
- sub_objects.clear ();
+ sub_objects.reinit (0,0);
// then associate new sparsity
// pattern and resize
reinit (const unsigned int n_block_rows,
const unsigned int n_block_columns)
{
- // delete previous content
+ // delete previous content and
+ // clean the sub_objects array
+ // completely
for (unsigned int i=0; i<rows; ++i)
for (unsigned int j=0; j<columns; ++j)
{
sub_objects[i][j] = 0;
delete sp;
};
- sub_objects.clear ();
+ sub_objects.reinit (0,0);
- // set new sizes
+ // then set new sizes
rows = n_block_rows;
columns = n_block_columns;
sub_objects.reinit (rows, columns);