Are you, or anyone else here, familiar with "singletons" ?
Hello,
the Singleton it's an OOP programming pattern. Patterns are building blocks for common programming tasks, and their usage was formalized by the famous (I STRONGLY suggest reading it, re-reading it and read it again, for anyone wanting to become a better C++ programmer...) book called "Design Patterns: Elements of Reusable Object-Oriented Software", written by what is usually know the "Gang of Four", here's a link:
http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612
Patterns presented in this book have specific names that are useful, when discussing between developers, in order to understand exactly what we are referring to. Patterns are not related to C++, it's possible to write a Singleton (or any pattern) with any OOP language. So, a pattern is not really a language element, is more like a defined method to do something.
The Singleton pattern is a way to allow "globals" in a more elegant and object oriented way. We all have read everywere that globals are evil, but sometimes can be useful. The Singleton is just a container for globals, that allows to use data C++ (or any similar OOP language) access protection features, to at least contain the mess that globals usually do, and wrap them up in a more maintainable way.
More info here:
http://en.wikipedia.org/wiki/Singleton_pattern
The Singleton is a very simple pattern, its main feature is that, there can be only ONE instance of a variable declared as a Singleton.
This is obtained in a very clever way, by making the constructor private. The variable is instead declared using an Instance() member function that "knows" if an instance of this Singleton class has already defined or not. If it has, the function will return the instance itself. If not, it will create the first istance.
So, the net effect would be that, if a variable has been declared as a Singleton (more correctly "has been declared with a type of a class made using the Singleton pattern"), there will be one variable of that type in the whole program. The pattern itself would automatically prevent to create another instance!
This is very useful as a container for global simulation variables and anything else that shouldn't be declared more than once.
I haven't seen the ESP sample but, I've used the Singleton pattern in several projects already, like the Cloud9 MB339 and F4 Phantom and of course the F/A-18 we did for Microsoft, and it really helps to keep the code tidy and readable in places were you would need globals, but you don't want the extra associated mess that comes with them.