Re: Globally accessible variables and functions?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Marina (someone_at_nospam.com)
Date: 04/08/04


Date: Thu, 8 Apr 2004 16:01:27 -0400

So then what's the difference between a singleton class, and a class with
all shared members? I mean as far as the end result of what you are trying
to accomplish.

"Dougal Fair" <dougal@dougalfair.com> wrote in message
news:40759dde.767702359@news.goldengate.net...
> On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
> <notfirstname@planet.nl> wrote:
>
> >Hi Douglas,
> >
> >I do not understand what you mean, with pay for that overhead, recreating
> >gives the posibility to free resources.
>
> I fill in some values of a few data members in the new() function - so
> there's that overhead, performance-wise.
>
>
> >
> >However what you ask is called in VB.net a Shared class, you make that by
> >setting all the methods and properties shared.
>
>
> But that doesn't create the member variables and initialize them, etc.
>
> I think I found the answer in making a "singleton" class - the class
> contains an instance of itself, and I use a function I'll call
> "Create", which will do:
>
>
> Public Shared Function Create() As clsMyApplication
> If oApp Is Nothing Then
> oApp = New clsMyApplication
> End If
>
> Return oMyApp
> End Function
>
>
> And then, wherever I need this object, I just "create" it:
>
> dim oMyApp As clsMyApplication = oMyApp.Create()
>
> Which will create the object if necessary, but otherwise will use the
> one that is already created. It seems to work well.
>
> >
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html
/vaconsharedmembers.asp
> >
> >
> >I hope this helps?
> >
> >Cor
> >
> >
>



Relevant Pages

  • Re: [PHP] Re: find (matching) person in other table
    ... Jared Farrish wrote: ... 'cause some members can be added to database by administrator and maybe they don't have email address at all. ... The letters represent the request/response data (what you're giving to get, ... The overhead and latency used to complete one request makes it a quicker, ...
    (php.general)
  • Creating a C++ like message loop in .NET threaded classes.
    ... the dirty work of writing the message handling macros in MFC. ... writing a singleton class that, at run time, will have its members invoked by ... Now I don't necessarily want the code of these members ... the object processes the message when its thread is ...
    (microsoft.public.dotnet.framework)
  • Re: function used by more than one class
    ... together the "global" variables shared by the class members, ... A singleton class is one that can only ever have one ... >namespaces, that's what you should use when you have a bunch of related ... >freestanding functions you want to group together. ...
    (microsoft.public.vc.mfc)