Article View: comp.doc.techreports
Article #14UCSC TR: Smart Pointers: They're Smart, but They're Not Pointers
From: Jean McKnight
Date: Fri, 07 Aug 1992 18:28
Date: Fri, 07 Aug 1992 18:28
70 lines
3925 bytes
3925 bytes
University of California at Santa Cruz
Baskin Center for Computer Engineering and Information Sciences
The following technical report is available electronically or as
a paper copy. Instructions for getting either follow the abstract.
UCSC-CRL-92-27 (available electronically as ucsc-crl-92-27.ps.Z)
SMART POINTERS: THEY'RE SMART, BUT THEY'RE NOT POINTERS
Daniel R. Edelson
July 1992, 22 pages (paper copy $6.00)
Abstract:
There are numerous times when a C++ user could benefit from a pointer
variant that has more functionality than is provided by the basic,
language-defined pointer. For example, type-accurate garbage
collection, reference counting, or transparent references to
distributed or persistent objects, might be implemented with classes
that provide pointer functionality. The C++ language directly
supports one kind of pointer substitute, the smart pointer, in the
form of overloadable indirection operators: -> and *.
In this paper we evaluate how *seamlessly* smart pointers can replace
raw pointers. The ideal is for client code not to care whether it is
using raw pointers or smart pointers. For example, if a typedef selects
whether raw or smart pointers are used throughout the program, changing
the value of the typedef should not introduce syntax errors.
Unfortunately, C++ does not support pointer substitutes well enough to
permit seamless integration. This paper presents the desired behavior
of smart pointers in terms of the semantics of raw pointers that the
smart pointers try to emulate. Then, we describe several ways of
implementing smart pointers. For each, we show cases in which the
smart-pointers fail to behave like raw pointers. From among the
choices, we explain which is the best for emulating the standard
pointer conversions.
*Accessors* are similar to smart pointers, but have certain advantages.
This paper discusses the differences between accessors and smart
pointers, and shows why our conclusions about type conversion behavior
also apply to accessors. Whether a programmer prefers smart pointers
or accessors, this paper shows the limitations and recommends an
implementation.
This technical report is available electronically through either
of the following methods:
1. through anonymous ftp from ftp.cse.ucsc.edu, in /pub/tr. Log in
as "anonymous", use your email address as your password, specify
"binary" before getting the file. Uncompress before printing.
2. by mail to automatic mail server rnalib@ftp.cse.ucsc.edu.
Put this command on the subject line or in the body of the message:
@@ send ucsc-crl-92-27.ps.Z from tr
To get the index or abstract list:
@@ send INDEX from tr
@@ send ABSTRACTS.1992 from tr
To get the list of the tr directory:
@@ list tr
To get the list of commands and their syntax:
@@ help commands
Order paper copies from: Technical Library, Baskin Center for Computer
Engineering & Information Sciences, UCSC, Santa Cruz CA 95064.
Purchase orders are not accepted. Checks or money orders must be
for U.S. dollars, payable through a U.S. bank, and made out to
"UC Regents".
Questions: jean@cse.ucsc.edu
===========================================================================
Co-moderator: Richard Golding, Computer & Information Sciences, UC Santa Cruz
compdoc-techreports-request@ftp.cse.ucsc.edu
Technical Details
Message-ID:
<15ugkmINN64g@darkstar.UCSC.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!olivea!hal.com!darkstar.UCSC.EDU!goldingShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!olivea!hal.com!darkstar.UCSC.EDU!golding From: jean@cse.ucsc.edu (Jean McKnight) Newsgroups: comp.doc.techreports Subject: UCSC TR: Smart Pointers: They're Smart, but They're Not Pointers Message-ID: <15ugkmINN64g@darkstar.UCSC.EDU> Date: 7 Aug 92 18:28:00 GMT Organization: University of California, Santa Cruz (CE/CIS Boards) Lines: 70 Approved: compdoc-techreports@ftp.cse.ucsc.edu NNTP-Posting-Host: willow.ucsc.edu Originator: golding@willow