Singleton pattern in C++

You should probably read up Alexandrescu’s book. Regarding the local static, I haven’t use Visual Studio for a while, but when compiling with Visual Studio 2003, there was one local static allocated per DLL… talk about a nightmare of debugging, I’ll remember that one for a while :/ 1. Lifetime of a Singleton The main … Read more

ok , global variable is condemned, singleton is despised, what’s the alternative?

A static class with static data members? But who cares. Static data members are just global variables with more politically correct packaging. Don’t let fashion override your common sense. There’s nothing wrong with using a plain old global variable. The singleton pattern is often overkill and annoying to type, and annoying when you are single … Read more

Serialize a Static Class?

There are never any instances of static classes: they are both abstract and sealed in the IL, so the CLR will prevent any instances being created. Therefore there is nothing to serialize. Static fields are never serialized, and that’s the only sort of state that a static class can have. Your question about XML serialization … Read more

WPF Single Instance Best Practices [closed]

There are Several choices, Mutex Process manager Named Semaphore Use a listener socket Mutex Mutex myMutex ; private void Application_Startup(object sender, StartupEventArgs e) { bool aIsNewInstance = false; myMutex = new Mutex(true, “MyWPFApplication”, out aIsNewInstance); if (!aIsNewInstance) { MessageBox.Show(“Already an instance is running…”); App.Current.Shutdown(); } } Process manager private void Application_Startup(object sender, StartupEventArgs e) { … Read more

Problems with Singleton Pattern

In a garbage collection environment it can be an issue with regards to memory management In typical singleton implementations, once you create the singleton you can never destroy it. This non-destructive nature is sometimes acceptable when the singleton is small. However, if the singleton is massive, then you are unnecessarily using more memory than you … Read more

When should the Singleton pattern NOT be used? (Besides the obvious)

Summary Version: You know how often you use globals? Ok, now use Singletons EVEN LESS. Much less in fact. Almost never. They share all the problems globals have with hidden coupling (directly impacting testability and maintainability), and often the “only one can exist” restriction is actually a mistaken assumption. Detailed Answer: The most important thing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)