|
Boost Users : |
From: hicks (hicks_at_[hidden])
Date: 2002-02-04 20:10:40
-------- Original Message --------
Subject: Re: [Boost-Users] Four Questions on boost::shared_ptr
Date: Tue, 05 Feb 2002 10:08:25 +0900
From: hicks <hicks_at_[hidden]>
To: Boost-Users_at_[hidden], Duane Murphy <duanemurphy_at_[hidden]>
References: <B8838630.133F2%darin_at_[hidden]>
<20020204170343.12718_at_[hidden]>
Hi
>>You should normally use std::vector unless you have some special reason to
>>use boost:: scoped_array and boost::shared_array. Those classes are provided
>>both for completeness, and because occasionally there are such special
>>reasons. But not often.
>
>I consider user vector<> often. However there is a cost. For a fixed size
>allocation of a buffer there is only the data allocated. If you use a
>vector<> the vector also includes (for most implementations) the current
>capacity, the current size, and the allocator.
There is another sometimes very big overhead incurred by std::vector,
and not incurred by by new T[]/ delete[].
Most implementions of std::vector will enter a loop and call a
destructor on each element of the array,
even if there is no machine code associated with that destructor. At
least Borlands
implemention of delete[] automatically detects this condition and does
not insert a loop to call the destructors.
This could be avoided if std::vector used a traits type to determine
whether to enter a loop calling destructors.
Craig Hicks
KGK Tokyo
Duane Murphy wrote:
>--- At Mon, 4 Feb 2002 00:28:32 -0800, Darin Adler wrote:
>
>>On 2/3/02 11:54 PM, "Jon Wang" <webmaster_at_[hidden]> <mailto:webmaster_at_[hidden]> wrote:
>>
>>>1. Mr Stroustrup said that there wasn't a need for auto_array, for "a
>>>
>better
>
>>>solution is to use a vector". So, should we use vector or
>>>scoped_array/shared_array?
>>>
>>You should normally use std::vector unless you have some special reason to
>>use boost:: scoped_array and boost::shared_array. Those classes are provided
>>both for completeness, and because occasionally there are such special
>>reasons. But not often.
>>
>
>I consider user vector<> often. However there is a cost. For a fixed size
>allocation of a buffer there is only the data allocated. If you use a
>vector<> the vector also includes (for most implementations) the current
>capacity, the current size, and the allocator.
>
>I would be interested in finding a class that is somewhere between
>allocating my own buffers and vector<>. Low overhead for simple
>allocations; no resizing or growing. Even in this case, in order to
>support iterator semantics the size is going to be needed.
>
>Sigh.
>
>I suppose a case like this might be when scoped_array would be used?
>
> ...Duane
>
>
>
>
>Info: <http://www.boost.org>
>Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
>Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net