singleton

Singleton code linker errors in vc 9.0. Runs fine in linux compiled with gcc

I have a simple logger that is implemented as a singleton. It works like i want when I compile and run it with g++ in linux but when I compile in Visual Studio 9.0 with vc++ I get the following errors. Is there a way to fix this? I don't mind changing the logger class around, but I would like to avoid changing how it is called. 1>Linkin...

private destructor for singleton class

Is it compulsory to have a private destructor for a singleton class. ...

Instantiation failure and singleton-behaviour interaction [NInject1]

I have set up a NInject (using version 1.5) binding like this: Bind<ISessionFactory>().ToMethod<ISessionFactory>(ctx => { try { // create session factory, might fail because of database issues like wrong connection string } catch (Exception e) { throw new DatabaseException(e); } }).Using<Singleto...

How to restrict the number of objects of a class to a given number in ruby?

how can i extend the singleton pattern to a number of objects for a class i.e. how can i have only 5 objects of a class at max and not more than that in ruby ...

object oriented programming in c++

how do i make only 1 object creation of any class? ...

Should we seal Singletons? Should we try to inherit from Singletons in the first place?

Should a Singleton class be allowed to have children? Should we seal it? What are the pro's and con's? For being able to inherit from a Singleton class, we would have to make the constructor protected instead of private. Now, that will be fine in c#, but the protected word in java gives both child-classes and package-classes access to t...

if i want to build logger class in c++ or java what should it be singletone or static

Hello all general question is i like to build logger class that writes to single log file from different classes in my application what should the logger class be singletone or static class ...

efficient thread-safe singleton in C++

The usual pattern for a singleton class is something like static Foo &getInst() { static Foo *inst = NULL; if(inst == NULL) inst = new Foo(...); return *inst; } However, it's my understanding that this solution is not thread-safe, since 1) Foo's constructor might be called more than once (which may or may not matter) and...

Builder pattern and persistent state : Test Data Builders

Does anyone have any links to some code they like that shows a good example of this in c#? As an example of bad code, here is what a builder I have now looks like. I'm trying to have a way to keep the flexibility of the builder pattern but not rebuild the properties. Cheers, Berryl public abstract class ActivityBuilder { public a...

how to create a system-wide independent universal counter object primarily for Database keys?

I would like to create/use a system-wide independent universal 'counter object' that can be called via COM in a thread-safe manner. The counter object will be passed an ID to identify which counter to return, handle the counting, 'persist' the count (occasionally), have reasonable performance (as fast as possible) perhaps capable of 10...

Extending a singleton class

i used to create an instance of a singleton class like this: $Singleton = SingletonClassName::GetInstance(); and for non singleton class: $NonSingleton = new NonSingletonClassName; i think we should not differentiate how we create an instance of a class whether this is a singleton or not. if i look in perception of other class, i d...

Example of Singleton pattern

Hi, Can anybody tell me a good example of Singleton pattern? Also I've one doubt to ask, Is the following scenario is that of singleton pattern: When we have many printers connected in LAN but only one printer queue? ...

Two questions on Singleton C#

Consider the following code public sealed class Singleton { private static readonly Singleton instance = new Singleton(); public static Singleton Instance { get { return instance; } } static Singleton() {} private Singleton() {} } Question 1) Here what is the purpose of static constructor ? (I know static cons...

Using singleton instead of a global static instance

I ran into a problem today and a friend recommended I use a global static instance or more elegantly a singleton pattern. I spent a few hours reading about singletons but a few things still escape me. Background: What Im trying to accomplish is creating an instance of an API and use this one instance in all my classes (as opposed to ma...

How do I find out if the variable is declared in Python?

I want to use a module as a singleton referenced in other modules. It looks something like this (that's not actually a code I'm working on, but I simplified it to throw away all unrelated stuff): main.py import singleton import printer def main(): singleton.Init(1,2) printer.Print() if __name__ == '__main__': pass singleto...

How to save data from multiple views of an iPhone app?

Hi Everyone. I'm making an app where I need to save the text in multiple views in the app when the app quits. I also need to be able to remove all of the data from just one of those views and when the app quits, it's possible not all of those views will have been created yet. After reading this post I thought perhaps it would be good ...

Is this a valid, lazy, thread-safe Singleton implementation for C#?

I implemented a Singleton pattern like this: public sealed class MyClass { ... public static MyClass Instance { get { return SingletonHolder.instance; } } ... static class SingletonHolder { public static MyClass instance = new MyClass (); } } From Googling around for C# Singleton implementat...

Singleton again, but with multi-thread and Objective-C

I know Singleton pattern has been discussed so much. But because I'm not fully understand the memory management mechanism in Objective-C, so when I combined Singleton implementation with multithreading, I got a big error and cost me a whole day to resolve it. I had a singleton object, let's call it ObjectX. I declared an object inside O...

Singleton class design in C#, are these two classes equivalent?

I was reading up on singleton class design in C# on this great resource and decided to go with alternative 4: public sealed class Singleton1 { static readonly Singleton1 _instance = new Singleton1(); static Singleton1() { } Singleton1() { } public static Singleton1 Instance { get { ...

Are Multiple singleton instances possible in a shared DLL?

I am going to develop a DLL for an MFC Application, and suppose I have a singleton class in this DLL with some synchronization mechanism. And this DLL is used by other processes, namely EXEs. The question is: is this singleton created only once for all sharing processes or every process has its own singleton? And How can I solve this mu...