On Tue, Jul 21, 2009 at 8:03 PM, Ed Lazor<[email protected]> wrote:
> On Tue, Jul 21, 2009 at 10:48 AM, troels knak-nielsen<[email protected]> 
> wrote:
>> Irey<[email protected]> wrote:
>>> That's a performance boost of 7X using a singleton versus not using a
>>> singleton.
>>
>> You're conflating two unrelated concepts.  The performance difference
>> that you observe is due to the difference between instantiating a new
>> object per iteration vs. reusing the same.
>
> Isn't that one of the benefits of using a singleton?

Yes, that's one of them. A big problem with singleton is that it does
two things. One one hand, it ensures a single instance in the
application, and on the other hand it provides a means to share this
instance. Those two things do not need to be coupled together.

>> You can reuse the same object in other ways than through a global symbol.
>
> Aren't singleton classes preferred over global variables?

Most people would say that, yes. And I agree, but I would really
prefer neither. Global variables and singletons and static methods and
static variables all share a similarity in that they are globally
scoped symbols. That makes all of them suspect.

--
troels

Reply via email to