From 3b183163c9ab8b5995cd7c3e832b0c79b57dfca9 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 10 May 2001 16:00:49 +0000 Subject: [PATCH] Clarify rationale for noncopyability [SVN r10085] --- scoped_array.htm | 17 +++++++++++------ scoped_ptr.htm | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scoped_array.htm b/scoped_array.htm index 3bf65cd..e317e21 100644 --- a/scoped_array.htm +++ b/scoped_array.htm @@ -15,16 +15,21 @@ allocated array. (Dynamically allocated arrays are allocated with the C++ ne expression.)   The array pointed to is guaranteed to be deleted, either on destruction of the scoped_array, or via an explicit scoped_array::reset().

Class scoped_array is a simple solution for simple -needs.  It cannot be used in C++ Standard Library containers.  See shared_array +needs. It supplies a basic "resource acquisition is +initialization" facility, without shared-ownership or transfer-of-ownership +semantics.  Both its name and enforcement of semantics (by being noncopyable) +signal its intent to retain ownership solely within the current scope.  By +being noncopyable, it is +safer than shared_array for pointers which should not be copied.

+

Because scoped_array is so simple, in its usual +implementation every operation is as fast as a built-in array pointer and it has no +more space overhead that a built-in array pointer.

+

It cannot be used in C++ Standard Library containers.  See shared_array if scoped_array does not meet your needs.

Class scoped_array cannot correctly hold a pointer to a single object.  See scoped_ptr for that usage.

-

Because scoped_array is so simple, in its usual -implementation every operation is as fast as a built-in array pointer and has no -more space overhead that a built-in array pointer.

-

A heavier duty alternative to a scoped_array is a scoped_ptr -to a C++ Standard Library vector.

+

A C++ Standard Library vector is a heavier duty alternative to a scoped_array.

The class is a template parameterized on T, the type of the object pointed to.   T must meet the smart pointer common requirements.

diff --git a/scoped_ptr.htm b/scoped_ptr.htm index 0e47606..27512d1 100644 --- a/scoped_ptr.htm +++ b/scoped_ptr.htm @@ -16,14 +16,21 @@ expression.)   The object pointed to is guaranteed to be deleted, either on destruction of the scoped_ptr, or via an explicit scoped_ptr::reset().  See example.

Class scoped_ptr is a simple solution for simple -needs.  It cannot be used in C++ Standard Library containers.  See shared_ptr +needs.  It supplies a basic "resource acquisition is +initialization" facility, without shared-ownership or transfer-of-ownership +semantics.  Both its name and enforcement of semantics (by being noncopyable) +signal its intent to retain ownership solely within the current scope.  By +being noncopyable, it is +safer than shared_ptr or std::auto_ptr for pointers which should not be +copied.

+

Because scoped_ptr is so simple, in its usual implementation +every operation is as fast as for a built-in pointer and it has no more space overhead +that a built-in pointer.

+

Class scoped_ptr cannot be used in C++ Standard Library containers.  See shared_ptr or std::auto_ptr if scoped_ptr does not meet your needs.

Class scoped_ptr cannot correctly hold a pointer to a dynamically allocated array.  See scoped_array for that usage.

-

Because scoped_ptr is so simple, in its usual implementation -every operation is as fast as a built-in pointer and has no more space overhead -that a built-in pointer.

The class is a template parameterized on T, the type of the object pointed to.   T must meet the smart pointer common requirements.

@@ -116,7 +123,7 @@ body is not visible at the time scoped_ptr<> deletes it. See ISO 5.3.5/5.  Note that some compilers will issue a warning even though the above code is well defined.


-

Revised 27 July 2000

+

Revised 10 May 2001

© Copyright Greg Colvin and Beman Dawes 1999. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is"