|
-
Jun 6th, 2001, 02:36 PM
#1
Thread Starter
Junior Member
dimension help please
If you have a procedure in your application that always creates an object named Inventory, although sometimes it is not necessary to do so. When an Inventory object is created, a delay occurs before the next statement executes. You would like to make the next statement execute more quickly when a member of the Inventory object does not need to be called or referenced. Which code should you use to dimension of the Inventory object?
a. Dim objInventory As Inventory
Set objInventory = CreateObject(Inventory)
b. Dim objInventory As Inventory
Set objInventory = New Inventory
c. Dim objInventory As Object
Set objInventory = New Inventory
d. Dim objInventory As New Inventory
-
Jun 6th, 2001, 05:40 PM
#2
Member
I'd say it must be D, because the one line of code would be faster to execute than the two lines of code that are contained in A, B, and C. Using the answer A would be really slow because you are using CreateObject and anyone that has used VB for any length of time knows that this function slows down a VB app considerably. Also with answers B and C using the Set statement is not really necessary. Answer D is basically doing the same thing in one line of code. Answer D would also be correct because it is the only one that would do exactly what you want. You are trying to make a new object Inventory. The others just reference the other object Inventory you already have.
I'd have to say the correct answer is definately D.
-
Jun 6th, 2001, 05:49 PM
#3
_______
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 6th, 2001, 05:49 PM
#4
No! Hate to dissagree but A is the fastest method. If your on a network and Are trying to createObject across the network then it is considerabley slower...but I am assuming your on 1 machine..so A would be fastest.
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 6th, 2001, 05:51 PM
#5
No wayne..sorry...but the answer is not Here...it is THERE
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 6th, 2001, 05:55 PM
#6
Fanatic Member
no, it's definatly c. you see, when you do that, you use late-binding, which is faster than the others. By calling it as an object, vb knows you want an ojbect, so it's easy to for it to figure out the best answer. it's all described here
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Jun 6th, 2001, 06:08 PM
#7
Member
I still say it has to be D. How can 2 lines of code ever be faster than one line of code. You're all wrong!!
geoff_xrx: I'm glad to see you agree with me. You did pick D, didn't you?
-
Jun 6th, 2001, 06:10 PM
#8
Re: dimension help please
Originally posted by jeffc
a. Dim objInventory As Inventory
Set objInventory = CreateObject(Inventory)
b. Dim objInventory As Inventory
Set objInventory = New Inventory
c. Dim objInventory As Object
Set objInventory = New Inventory
d. Dim objInventory As New Inventory
Let's analyze.
A. Using a function is faster, but when used in conjuction with the Set keyword, it slows the process down quite a bit. This is not true, however, if the program is run over a network. But only if the program is on the server, not the clients. Because the client system must get permission for everthing.
C. You should always be as specific as possible when dimensioning a variable. When dimensioning a variable as an Object, VB must load and allocate several different dynamic link libraries and active-x directories in order to set the object to the one you specify later. However the usual rules of option A. apply here, too.
D. Don't do this. This method forces your application to refresh every variable in the program. Use of the New keyword is not recommended by MSDN. The process is very time comsuming. The OS is forced to allocate pointers for all variables, dump the used RAM, and reallocate space in the RAM for the variables.
for more information, check geoff_xrx's idea, or Wayne's idea
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 6th, 2001, 06:10 PM
#9
BTW : The answer is E
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 6th, 2001, 06:19 PM
#10
Member
crptcblade: You must remember that Microsoft recommends dumping used RAM after the first couple lines of every program. I usually do this in the Form_Activate event, but you could also use it in the Form_Load event. If you use the code in answer D, you don't have to put the call to the function UsedRAMDump() in the Form_Activate. Answer D will automatically cause all used RAM to be dumped. This would save a line of code that doesn't have to be executed. Also note that dumping used RAM also gives the CPU more RAM to use to execute your program.
The answer is D...
-
Jun 6th, 2001, 06:22 PM
#11
Ahh yes. I forgot that the UsedRAMDump() function is included in answer D. Too much watching TV while trying to remember specifics.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 6th, 2001, 06:46 PM
#12
Fanatic Member
i prefer to use the DumpRAM (App.ProccessID) method, it runs faster
GWDASH
[b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]
-
Jun 6th, 2001, 11:06 PM
#13
Member
gwdash: evidently you have never used the DumpRAM (App.ProccessID) method. If you had you would have realized that this method not only dumps the used RAM it dumps all of your RAM. Dumping unused RAM leaves no RAM for Windows to use. Therefore, you would see the Blue Screen of Death as soon as this method was executed.
The DumpRAM(App.ProcessID) method is to be used only by Windows after it has begun the shutdown process. This dumps all RAM so that the computer can say "It is now safe to turn off your computer." without telling a lie. This is the only safe use for this method. As stated before, for dumping used RAM the UsedRAMDump() function should be used.
-
Jun 6th, 2001, 11:22 PM
#14
Registered User
Best practice is B which uses early binding as well as allowing you to control when you instantiate an object.
This is valuable as you say the proc does not always need to create the object: "although sometimes it is not necessary to do so." I always use B, and cringe when I see D used.
Late binding (A & C) is slowest as the binding process is complete at run time and is performed any time the variable is referenced. As you can imagine this takes a lot of time, plus you miss out on intellisense.
Come on guys aren't we all here to help each other?
Last edited by Nucleus; Jun 6th, 2001 at 11:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|