Tips and Tricks
Consider constructing the type name on-the-fly. This can save time and memory. As an example, consider the TV_ttf_display_type for BoundsCheckedArray<T> we discussed earlier:
template <class T>
int TV_ttf_display_type ( const BoundsCheckedArray<T> *a )
char type [ 4096 ];
snprintf ( type, sizeof ( type ), "value_type[%d]", a->get_size () );
(void) TV_ttf_add_row ( "array_values", type, a->get_array () );
return TV_ttf_format_ok;
Note how we constructed an array type. The alternative would be to iterate a->get_size () times calling TV_ttf_add_row (). Depending on the number of elements, this could exhaust the API's buffer. In addition, there is a time penalty since TotalView will need to handle each line added by TV_ttf_add_row separately.
Constructing the array type as we did not only eliminates these disadvantages, it also provides other advantages. For example, as TotalView now knows that what is being presented is really an array, all the normal operations on arrays such as sorting, filtering, etc. are available.