Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
The detection of dangling references in C++ programs
Eyre-Todd R. ACM Letters on Programming Languages and Systems2 (1-4):127-134,1993.Type:Article
Date Reviewed: Mar 1 1995

A technique for implementing so-called smart pointers, which detect dangling references, in C++ is described. Smart pointers are objects of special classes with overloaded operators for dereferencing and structure access; they mimic regular pointers but provide some additional smarts. Typical applications for smart pointers are garbage collection (to retire unused objects) and distributed computing (to access remote objects). The author’s technique marks each object with a unique identifying number and replicates that number in all pointers to the object. When the object is deallocated through one pointer, and the memory location is later accessed through one of the other pointers, the dangling reference has a high likelihood of being detected, since the identifying number stored with the pointer is unlikely to match the number that happens to be at the inspected storage location in the heap (which may be inside the free list or another live object).

The cost of the technique is obvious. Each pointer, and each object, must carry an added integer. More important, the outlined implementation places the object identifiers in a common base class and requires that all classes that aim to benefit from the detection scheme derive from that class. In practice, that requirement is likely to be cumbersome.

The paper gives sufficient detail of the C++ implementation to allow someone skilled in the art of C++ templates and operator overloading to replicate it. The author gives some useful hints on structuring code to facilitate turning the checking on and off when switching between test and release versions. The author suggests that the method can be extended to pointers to constant objects, a common C++ idiom. That is in fact true, but the extension to polymorphic pointers, the cornerstone of virtual dispatch in C++, is known to be much more difficult and far from seamless. Unfortunately, no quantitative measurements of the time and space cost of the scheme are provided.

Reviewer:  C. S. Horstmann Review #: CR118404
Bookmark and Share
 
Dynamic Storage Management (D.3.3 ... )
 
 
Data Types And Structures (D.3.3 ... )
 
 
Debugging Aids (D.2.5 ... )
 
 
Language Constructs and Features (D.3.3 )
 
 
Object-Oriented Programming (D.1.5 )
 
 
Testing And Debugging (D.2.5 )
 
Would you recommend this review?
yes
no
Other reviews under "Dynamic Storage Management": Date
Reducing the latency of a real-time garbage collector
Johnson R. ACM Letters on Programming Languages and Systems 1(1): 46-58, 1992. Type: Article
Oct 1 1993
On mobile Java memory consumption
Hartikainen V., Liimatainen P., Mikkonen T.  Parallel, distributed, and network-based processing (Proceedings of the 14th Euromicro International Conference on Parallel, Distributed, and Network-Based Processing (PDP’06), Feb 15-17, 2006)333-339, 2006. Type: Proceedings
Mar 1 2007
Shared heap management for memory-limited Java virtual machines
Choi Y., Han H. ACM Transactions on Embedded Computing Systems 7(2): 1-32, 2008. Type: Article
Aug 15 2008
more...

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy