Thread: Still on the subject of Singletons (their usage)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    Still on the subject of Singletons (their usage)

    Never thought I'd ask this. Since most texts about the singleton pattern focus on its implementation, it hardly occurred to me that I would be facing dilemas concerning their actual usage.

    GameMap is a GoF Singleton returning a reference through getInstance(). The problem is that I'm really not sure what to do with its copy constructor and assignment operator.

    My first thought was to explicitly declare them in order to make it clear to users of the class they can use them. GameMap implements a vector of hexagons and is meant to be used in various contexts by other objects and routines.

    Because of this, I believe it is more practical to write:

    GameMap myMap = GameMap::getInstance();

    Than it is to make copy-control private and have to write something like the following everytime I need to access the container's contents interface:

    GameMap::getInstance().Hexagon(16, 7).hasRoad()

    At best I can simplify a bit by renaming getInstance() to Map(), for instance. But still feels awkward to rely on a temporary all the time.

    I see too much singleton implementations moving copy-control to the private portion of the class definition. So, i'm a little shaky about not doing it. Should I?
    Last edited by Mario F.; 07-23-2007 at 08:04 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reduce CPU usage
    By patrick22 in forum Windows Programming
    Replies: 9
    Last Post: 07-10-2009, 02:13 PM
  2. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  3. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  4. Win2K Limiting CPU Usage?
    By drdroid in forum Tech Board
    Replies: 4
    Last Post: 03-31-2004, 02:08 PM
  5. Parsing e-mail headers for subject field
    By SMurf in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2002, 02:57 AM