Boost logo

Boost Users :

From: David Daeschler (daveregs_at_[hidden])
Date: 2007-04-25 15:31:57


Hi Michael,

Straight out of the docs
http://www.boost.org/libs/smart_ptr/scoped_array.htm

> 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.

IMHO saying that the change to an array pointer is an "optimization" at
all is dubious.

-Dave

On Wed, 2007-04-25 at 13:33 -0500, Michael Marcin wrote:
> Hello,
>
> I have a new programmer on my team who has been brought on as an
> optimization engineer. She has a lot more experience than I do but I fear
> some of that experience may have left impressions that have stuck with her
> for too long. On the first check in labeled spot optimizations there were
> many things changed that disturbed me. One of them was changing a class
> from essentially.
>
> #include <boost/scoped_array.hpp>
> class Context
> {
> public:
> Context( unsigned int width, unsigned int height )
> : m_buffer( new unsigned int[width*height] )
> {
> }
>
> unsigned int* GetBuffer() { return m_buffer.get(); }
> private:
> boost::scoped_array<unsigned int> m_buffer;
> };
>
> to
>
> class Context
> {
> public:
> Context( unsigned int width, unsigned int height )
> : m_buffer( new unsigned int[width*height] )
> {
> }
> ~Context()
> {
> delete m_buffer;
> }
>
> inline unsigned int* GetBuffer() { return m_buffer; }
> private:
> unsigned int* m_buffer;
> };
>
>
> First of all there is the defect of delete being called instead of delete[].
> Other than that I was under the impression that there should be no
> difference between the two other than the former being more descriptive (it
> instantly tells me this is an array and the memory is owned by the instance
> of this class).
>
> Is this really an optimization?
>
> Thanks,
>
> Michael Marcin
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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