How expensive is object instantication?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sam.s.kong@gmail.com

    How expensive is object instantication?

    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.a sp"-->
    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

  • Justin Piper

    #2
    Re: How expensive is object instantication?

    On Wed, 04 Oct 2006 11:47:15 -0500, <sam.s.kong@gma il.comwrote:
    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.
    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]

    --
    Justin Piper
    Bizco Technologies
    We help businesses optimize efficiency with information technology, audio-visual, and mobility solutions through predictable pricing and dependable support.

    Comment

    • sam.s.kong@gmail.com

      #3
      Re: How expensive is object instantication?

      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

      Comment

      • Patrice

        #4
        Re: How expensive is object instantication?

        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

        <sam.s.kong@gma il.coma écrit dans le message de news:
        1159980435.6190 25.312710@h48g2 00...legr oups.com...
        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.a sp"-->
        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
        >

        Comment

        • Justin Piper

          #5
          Re: How expensive is object instantication?

          On Wed, 04 Oct 2006 12:13:49 -0500, <sam.s.kong@gma il.comwrote:
          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]).

          --
          Justin Piper
          Bizco Technologies
          We help businesses optimize efficiency with information technology, audio-visual, and mobility solutions through predictable pricing and dependable support.

          Comment

          • Anthony Jones

            #6
            Re: How expensive is object instantication?


            "Justin Piper" <jpiper@bizco.c omwrote in message
            news:op.tgwrd0u zcs3d1w@luxembo urg.psg.bizcote ch.com...
            On Wed, 04 Oct 2006 12:13:49 -0500, <sam.s.kong@gma il.comwrote:
            >
            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/

            Comment

            • Anthony Jones

              #7
              Re: How expensive is object instantication?


              <sam.s.kong@gma il.comwrote in message
              news:1159980435 .619025.312710@ h48g2000cwc.goo glegroups.com.. .
              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.a sp"-->
              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
              >

              Comment

              Working...