Premium
The implementation of generic smart pointers for advanced defensive programming
Author(s) -
Savidis Anthony
Publication year - 2004
Publication title -
software: practice and experience
Language(s) - English
Resource type - Journals
SCImago Journal Rank - 0.437
H-Index - 70
eISSN - 1097-024X
pISSN - 0038-0644
DOI - 10.1002/spe.600
Subject(s) - computer science , memory leak , pointer (user interface) , garbage collection , memory safety , indirection , pointer analysis , programming language , heap (data structure) , garbage , macro , operating system , c dynamic memory allocation , exception handling , call stack , manual memory management , database , memory management , overlay , stack (abstract data type) , static analysis , computer hardware , software
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. Copyright © 2004 John Wiley & Sons, Ltd.