   Singleton Query
  Is there any way to implement singletons portably?Some people talk about scope based ACE_Guards<>. Can anyone explain a bit about this?Earlier I posted this in game programming by mistake. Moderator please remove that thread. Sorry for inconvenience.[Edited by - Japanese on June 22, 2006 11:02:11 AM]
  What do you mean by a portable implementation of the singleton pattern? Whatever your language is, if you comply to the diffrent language rules then your implementation will be protable. And what's the deal with ACE_guards? It looks like this is tied to a library called ACE - which has nothing to do with a portable implementation of the singleton pattern. Can you be more precise about your exact needs?Please, edit your thread title - it has nothing to do with your question, and unless you don't want us to answer your questions (which would be rather odd) I suggest you match your thread titles with your questions. We don't read any single thread on gdnet just to know what their subject is. Regards,   ;  Thanks for your replyWhat I am asking is can we use ACE library to make portable singletons?   ;  But what do you mean by portable singletons? How aren't regular singletons portable?   ;Quote:Original post by JapaneseThanks for your replyWhat I am asking is can we use ACE library to make portable singletons?The goal of ACE is very specific. ACE is a communication library (Adaptive Communicative Environment). From this page, Quote:The ADAPTIVE Communication Environment (ACE) is a freely available, open-source object-oriented (OO) framework that implements many core patterns for concurrent communication software.AndQuote:It simplifies the development of OO network applications and services that utilize interprocess communication, event demultiplexing, explicit dynamic linking, and concurrency.If this description fit your needs, then feel free to use ACE. If it is not the case, then you don't have to use ACE. C++ is a standardized language, meaning that compiler should obbey to the standard, whatever their target platform is. It means that your singleton will be portable if you use only pure, standardized C++ - ie you don't have to use another library to improve the portability of your own code, unless there is a real need. Franckly, ACE singleton seems rather complicated. It works in conjunction with the ACE object manager, and support multithreaded locking policies. It also have a cleanup function (something that I often advertise to be rather bad, since a providing a cleanup function means that this function will be used, resulting in possible runtime errors when you'll want to gain access to your singleton after its destruction). The GoF singleton, while beeing rather simple, provide a good and efficient - albeit leaking - implementation. For a better, standard proff implementation, you can check Loki's singleton (policy based singleton written by Andrei Alexandrescu). Th ekey thing is that you don't need to use ACE to be able to create portable singleton - of course, if you are using ACE you might want to use its object manager to manage your singleton lifetime (but I bet this will be rather tricky).Regards,and thanks for the thread title :)   ;  No, you can't really, for two reasons:1) If you use any library to implement a singleton, than you are implicitly limited to the portability of that library.2) Is this the library you are talking about? It appears to be a network programming toolkit, which has nothing to do with the concept of a singleton. All of the fancy stuff it does is entirely unneccessary as far as portable singletons go.You can create a portable singleton implementation using only standard C or C++, you don't need any libraries (not even the standard library!) to do so.However, I strongly urge you to reconsider your design because singletons are generally suggest a bad design or the start of a bad design.   