How expensive is object instantication?

Discussion in 'ASP General' started by sam.s.kong@gmail.com, Oct 4, 2006.

  1. Guest

    Hi,

    I'm doing an ASP project in VBScript.
    In VBScript, there's no namespace and no static method (class method).
    Thus, what I'm trying to do is to make a clas, define instance methods
    in the class, create a global object and call the instance methods.
    It will simulate a namespace.
    My concern is that what's the overhead.

    -----------Example----------

    [library.asp]

    class MyClass
    function F1
    ....
    end function

    function F2
    ....
    end function
    end class

    set G = new MyClass 'This will be always created even if it's not used
    at all.

    [some_page.asp]
    <!--#include file="library.asp"-->
    G.F1
    G.F2

    -------------------------

    What do you think?
    Is it good or bad?
    And why so?

    If you have any other suggestions about namespace, share with me
    please.

    Thanks.

    Sam
     
    , Oct 4, 2006
    #1
    1. Advertising

  2. Patrice Guest

    If you do nothing in the initialize event, it is likely small compared with
    DB access etc... Also this is the kind of question that is easily solved by
    testing...

    Another option would be to use a prefix before your the sub name (i.e.
    something like G_F1 or glbF1)
    --
    Patrice

    <> a écrit dans le message de news:
    ...
    > Hi,
    >
    > I'm doing an ASP project in VBScript.
    > In VBScript, there's no namespace and no static method (class method).
    > Thus, what I'm trying to do is to make a clas, define instance methods
    > in the class, create a global object and call the instance methods.
    > It will simulate a namespace.
    > My concern is that what's the overhead.
    >
    > -----------Example----------
    >
    > [library.asp]
    >
    > class MyClass
    > function F1
    > ....
    > end function
    >
    > function F2
    > ....
    > end function
    > end class
    >
    > set G = new MyClass 'This will be always created even if it's not used
    > at all.
    >
    > [some_page.asp]
    > <!--#include file="library.asp"-->
    > G.F1
    > G.F2
    >
    > -------------------------
    >
    > What do you think?
    > Is it good or bad?
    > And why so?
    >
    > If you have any other suggestions about namespace, share with me
    > please.
    >
    > Thanks.
    >
    > Sam
    >
     
    Patrice, Oct 4, 2006
    #2
    1. Advertising

  3. Guest

    Hi Justin,

    Justin Piper wrote:
    > You could do it this way instead. It avoids creating the object unless
    > it is needed, and it guarantees that the class will be instantiated by
    > the time it is used.
    >
    > G.F1
    >
    > Function G()
    > If IsEmpty([G::Inst]) Then Set [G::Inst] = New MyClass
    > Set G = [G::Inst]
    > End Function
    >
    > Class MyClass
    > Function F1() : End Function
    > End Class
    >
    > Dim [G::Inst]


    Excellent!
    That way, I can delay the instantication until it's first used.
    So, basically you think that wrapping functions in a class is a good
    workaround to simulate namespaces?

    By the way, I've never seen a notation like [G::Inst].
    Is it a valid syntax?

    Thanks.

    Sam
     
    , Oct 4, 2006
    #3
  4. "Justin Piper" <> wrote in message
    news:eek:...
    > On Wed, 04 Oct 2006 12:13:49 -0500, <> wrote:
    >
    > > Hi Justin,
    > >
    > > Justin Piper wrote:
    > >> You could do it this way instead. It avoids creating the object unless
    > >> it is needed, and it guarantees that the class will be instantiated by
    > >> the time it is used.
    > >>
    > >> G.F1
    > >>
    > >> Function G()
    > >> If IsEmpty([G::Inst]) Then Set [G::Inst] = New MyClass
    > >> Set G = [G::Inst]
    > >> End Function
    > >>
    > >> Class MyClass
    > >> Function F1() : End Function
    > >> End Class
    > >>
    > >> Dim [G::Inst]

    > >
    > > Excellent!
    > > That way, I can delay the instantication until it's first used.
    > > So, basically you think that wrapping functions in a class is a good
    > > workaround to simulate namespaces?

    >
    > The only other way to simulate namespaces I can think of is to adopt a
    > naming convention that includes the namespace name:
    >
    > Function [G::F1]() : End Function
    >
    > Function Main()
    > Dim F1: Set F1 = GetRef("G::F1")
    >
    > F1()
    > End Function
    >
    > That might be useful if you wanted to break the G namespace into
    > multiple files.
    >
    > > By the way, I've never seen a notation like [G::Inst].
    > > Is it a valid syntax?

    >
    > It's a quoted identifier. They're not very useful in general, so I tend
    > to use them to indicate that one identifier has some relationship to
    > another (e.g, I probably would have named the class [G::Impl]).
    >


    If you had that much complexity that a namespace needed to be split into
    seperate files you wouldn't be building your class hiearchy in VBScript.


    > --
    > Justin Piper
    > Bizco Technologies
    > http://www.bizco.com/
     
    Anthony Jones, Oct 5, 2006
    #4
  5. <> wrote in message
    news:...
    > Hi,
    >
    > I'm doing an ASP project in VBScript.
    > In VBScript, there's no namespace and no static method (class method).
    > Thus, what I'm trying to do is to make a clas, define instance methods
    > in the class, create a global object and call the instance methods.
    > It will simulate a namespace.
    > My concern is that what's the overhead.
    >
    > -----------Example----------
    >
    > [library.asp]
    >
    > class MyClass
    > function F1
    > ....
    > end function
    >
    > function F2
    > ....
    > end function
    > end class
    >
    > set G = new MyClass 'This will be always created even if it's not used
    > at all.
    >
    > [some_page.asp]
    > <!--#include file="library.asp"-->
    > G.F1
    > G.F2
    >
    > -------------------------
    >
    > What do you think?
    > Is it good or bad?
    > And why so?
    >


    It's a good idea. I use this approach a lot avoid function name collision
    between multiple include files and/or functions in the page.

    The only thing you need to be careful of then is that the class names that
    you use will not collide but since there are far fewer of them that's fairly
    easy.




    > If you have any other suggestions about namespace, share with me
    > please.
    >
    > Thanks.
    >
    > Sam
    >
     
    Anthony Jones, Oct 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg

    Least expensive server pdf control?

    John Dalberg, Sep 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    384
    John Dalberg
    Sep 15, 2005
  2. Mickey Segal
    Replies:
    3
    Views:
    2,306
    Mickey Segal
    Jul 10, 2003
  3. Replies:
    3
    Views:
    2,940
    Thomas Hawtin
    Dec 11, 2005
  4. Monster

    how are exception expensive?

    Monster, Apr 29, 2004, in forum: C++
    Replies:
    3
    Views:
    815
    jeffc
    Apr 30, 2004
  5. Dave
    Replies:
    4
    Views:
    416
    Robert Klemme
    Jan 28, 2007
Loading...

Share This Page