473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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.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 '06 #1
6 1378
On Wed, 04 Oct 2006 11:47:15 -0500, <sa********@gmail.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
http://www.bizco.com/
Oct 4 '06 #2
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 '06 #3
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

<sa********@gmail.coma écrit dans le message de news:
11**********************@h48g2000cwc.googlegroups. 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.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 '06 #4
On Wed, 04 Oct 2006 12:13:49 -0500, <sa********@gmail.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
http://www.bizco.com/
Oct 4 '06 #5

"Justin Piper" <jp****@bizco.comwrote in message
news:op***************@luxembourg.psg.bizcotech.co m...
On Wed, 04 Oct 2006 12:13:49 -0500, <sa********@gmail.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/

Oct 5 '06 #6

<sa********@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr 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.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

Oct 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PerfectDayToChaseTornados | last post by:
Hi All, I was wondering what peoples opinions, or experience were with creating instances by reflection. How expensive is the following code? It is from a factory class, I was wondering whether to...
7
by: Jason Heyes | last post by:
I have a class with an expensive copy, read and write. There are many objects of this class used throughout my program. What kind of encapsulation of this class do I use to make sure copy, read and...
57
by: Bill Cunningham | last post by:
I have a C question that may be OT so if no one wants to respond that's their perogative. Using standard C as a base. How can one begin to build a GUI system? Obviously there must be access to...
9
by: Vikram | last post by:
I was just curious to know how are calls like say dynamic_cast implemented. Is it really expensive to get the exact type of an object being pointed to by the baseclass pointer? The reason I am...
4
by: gnewsgroup | last post by:
We all seem to know that database connections are expensive and we try to reduce the number of database trips as much as possible. This may sound like a stupid question: What makes a database...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
8
by: SpaceMarine | last post by:
hello, my web app form has many DropDownLists that pull their content from a database. these calls are in a Business Access Layer, when first checks the context's Cache object for existing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.