Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualachild

Posted 30 October 2012 - 11:53 AM

An alternative type of having an instance in itself (I realize this isn't exactly what you're trying to do)
class Profiler {
public:
Profiler();
~Profiler() { }
// This gives us a global version without limiting us to only 1.  We can make other Profiler
// objects if we want.
static Profiler &GetGlobalInstance() {
  static Profiler prof;
  return prof;
}
[...] stuff
};
Then, you know, modify it accordingly if you need an instance per thread, or if you need to ensure synchronization is handled, or whatever.

#2achild

Posted 30 October 2012 - 11:51 AM

An alternative (what are you trying to do anyway?)
class Profiler {
public:
Profiler();
~Profiler() { }
// This gives us a global version without limiting us to only 1.  We can make other Profiler
// objects if we want.
static Profiler &GetGlobalInstance() {
  static Profiler prof;
  return prof;
}
[...] stuff
};
Then, you know, modify it accordingly if you need an instance per thread, or if you need to ensure synchronization is handled, or whatever.

#1achild

Posted 30 October 2012 - 11:50 AM

An alternative (what are you trying to do anyway?)
class Profiler {
public:
Profiler();
~Profiler() { }
// This gives us a global version without limiting us to only 1.  We can make other Profiler
// objects if we want.
static Profiler &GetGlobalInstance() {
  static Profiler prof;
  return prof;
}
[...] stuff
};
Then, you know, add stuff if you need an instance per thread, or if you need to ensure synchronization is handled, or whatever.

PARTNERS