-
Feb 22nd, 2021, 01:46 PM
#1
Thread Starter
Member
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?
-
Feb 22nd, 2021, 02:07 PM
#2
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.
-
Feb 22nd, 2021, 05:30 PM
#3
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
-
Feb 22nd, 2021, 09:34 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|