Results 1 to 4 of 4

Thread: vb.net MEMORY problems

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2018
    Posts
    41

    vb.net MEMORY problems

    Hi

    Which is less memory for vb.net program?

    dim i as integer (10 time dim as integer) or an array with 10 item (integer)

    same in string
    dim i as string
    dim i as string
    ...
    vs
    array with 10 item as string?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: vb.net MEMORY problems

    An array (or an alternative such as a List()) needs to store the items within it, plus a small amount of extra data for itself.

    It should be noted however that the extra memory usage is totally ignorable in almost every situation you can imagine. You should only spend time thinking about it if you have very limited memory (so that a extra few KB is a big deal) and also have thousands of arrays/lists/etc.

    For this it is much better to just write the code in the way that is easiest to maintain, which probably means using arrays etc.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,047

    Re: vb.net MEMORY problems

    You're going to have to explain what constraints you are working with. It's quite likely that it can't be totally determined, despite what Si said being technically true. After all, if these are local variables, they'd be on the stack, which means they either take up a little memory, or no memory at all, depending on how you look at it (once the stack frame goes away, so does the memory usage, so the memory usage can be seen as ephemeral). Also, in some scenarios, memory objects were tied to some boundary for efficiency sake, which could, in theory, mean that the memory taken up by any particular item could be variable. I don't know whether that is or is not the case anymore, because it doesn't matter to me, but it once was true.

    So, given the vagaries surrounding memory usage in a modern computer, what is the environment you work in such that this question even matters?
    My usual boring signature: Nothing

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,352

    Re: vb.net MEMORY problems

    The question is irrelevant to a VB.NET programmer. You should use the option that is more appropriate to the specific scenario. That may be the array in some cases and the discrete variables in others. If this is for a homework question or the like then you should be making efforts to work it out for yourself by doing some actual research, rather than having others doing your work for you.

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