Re: [Boost-users] Does shared_array's get() method introduceruntimeoverhead?
I have the following two code segments. I'm wondering if
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sohail Somani there is any
run time overhead of the get() method. Shall I use the latter one instead of the former one?
boost::shared_array a(new int[100]); for(int i = 0; i < 100; ++ i) a[i] = i;
boost::shared_array a(new int[100]); int a_ptr = a.get(); for(int i = 0; i < 100; ++ i) a_ptr[i] = i;
I'd guess not (from shared_array.hpp):
template<class T> class shared_array { ... T * get() const // never throws { return px; } ...
Unless that doesn't get inlined of course.
[snip smart-ass comment] Argh, of course I meant to paste: T & operator[] (std::ptrdiff_t i) const // never throws { BOOST_ASSERT(px != 0); BOOST_ASSERT(i >= 0); return px[i]; }
On 10/24/06, Sohail Somani
I have the following two code segments. I'm wondering if
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sohail Somani there is any
run time overhead of the get() method. Shall I use the latter one instead of the former one?
boost::shared_array a(new int[100]); for(int i = 0; i < 100; ++ i) a[i] = i;
boost::shared_array a(new int[100]); int a_ptr = a.get(); for(int i = 0; i < 100; ++ i) a_ptr[i] = i;
I'd guess not (from shared_array.hpp):
template<class T> class shared_array { ... T * get() const // never throws { return px; } ...
Unless that doesn't get inlined of course.
[snip smart-ass comment]
Argh, of course I meant to paste:
T & operator[] (std::ptrdiff_t i) const // never throws { BOOST_ASSERT(px != 0); BOOST_ASSERT(i >= 0); return px[i]; }
Does it mean that code segment 1 is as fast as segment 2, but code segment 3 is the slowest? ///////1 boost::shared_array a(new int[100]); for(int i = 0; i < 100; ++ i) a.get()[i] = i; ////////2 boost::shared_array a(new int[100]); int a_ptr = a.get(); for(int i = 0; i < 100; ++ i) a_ptr[i] = i; ////////3 boost::shared_array a(new int[100]); for(int i = 0; i < 100; ++ i) a[i] = i;
participants (3)
-
Peng Yu
-
Sebastian Redl
-
Sohail Somani