Results 1 to 14 of 14

Thread: dimension help please

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2001
    Location
    NY
    Posts
    17

    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

  2. #2
    Member
    Join Date
    May 2001
    Location
    Space...The Final Frontier
    Posts
    33
    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.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    The answer is Here
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    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"

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    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"

  6. #6
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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]

  7. #7
    Member
    Join Date
    May 2001
    Location
    Space...The Final Frontier
    Posts
    33
    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?

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  9. #9
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    BTW : The answer is E

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  10. #10
    Member
    Join Date
    May 2001
    Location
    Space...The Final Frontier
    Posts
    33
    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...

  11. #11
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  12. #12
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    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]

  13. #13
    Member
    Join Date
    May 2001
    Location
    Space...The Final Frontier
    Posts
    33
    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.

  14. #14
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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
  •  



Click Here to Expand Forum to Full Width