The implementation of generic smart pointers for advanced defensive programming

  • Authors:
  • Anthony Savidis

  • Affiliations:
  • Institute of Computer Science, Foundation for Research & Technology--Hellas, Heraklion, Crete, Greece

  • Venue:
  • Software—Practice & Experience
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Smart pointers denote a well-known technique for collective resource ownership, e.g. sharing dynamic object instances, while usually supporting automatic garbage collection based on reference counting. The original method has been retargeted to serve as a generic defensive programming method for 'exhaustive tracking' of erroneous pointer use in C++. Automatic bug tracking is supported in a unified manner both for pointers to heap memory, i.e. free storage, as well as for pointers to stack or global memory, i.e. auto or static storage. Overall, the presented technique (a) offers a simple contract for memory allocation and use; (b) supports type and indirection depth genericity; (c) implements most operators supported for built-in pointers with embedded bug defense; (d) offers an alternative way of employing a garbage collection facility for memory leak detection; and (e) provides an appropriate collection of utility macros, through which defensive pointers should be used, with an alternative version re-targeted to normal native pointers.