-
Aug 28th, 2015, 07:58 AM
#1
Thread Starter
Lively Member
Best way to empty an element of a multidimensional array.
I'm thinking I have significant memory depletion in a data collection application.
I am adding Erase arrayNm(1, 2) to kill certain arrays that are known empty at some points.
I have 64 inputs filling multiple arrays in different intermediate stages of data collection.
But can one empty individual array elements? From what I've read, maybe not?
Last edited by Enrique_; Aug 28th, 2015 at 08:36 AM.
-
Aug 28th, 2015, 08:45 AM
#2
Re: Best way to empty an element of a multidimensional array.
What do you mean 'empty'? At any time you can set individual elements of arrays to 'blank' (string arrays), or to 0 (numerical arrays).
Difficult to understand what you are really trying to do here...empty the entire array, or reset some individual elements of some array(s).
-
Aug 28th, 2015, 08:47 AM
#3
Re: Best way to empty an element of a multidimensional array.
Not sure what arrayNm is, but you can't use Erase to clear array elements from any array. Erase() clears the entire array.
If your array is declared static, i.e., size in the Dim statement like Dim X(10), then the array will always reserve memory whether or not Erase() is used. Memory used is total number of elements * byte size per element
If your array is declared dynamic, i.e., unsized like: Dim X(), then the all memory for the array is purged when Erase() is used.
You cannot purge memory for specific array elements where those elements are not strings/objects. If elements are objects/strings, then setting that array item to vbNullString or Nothing (as applicable) does clear the reference of that array item, but the array item still exists and has a value of zero
If the above doesn't really apply to your scenario, maybe you can provide more details, especially how arrayNm() is declared and ReDim'd if applicable.
Edited: You can trim a multidimensional array by resizing the last dimension to a lower value.
Last edited by LaVolpe; Aug 28th, 2015 at 08:51 AM.
-
Aug 28th, 2015, 11:25 AM
#4
Thread Starter
Lively Member
Re: Best way to empty an element of a multidimensional array.
Thanks for your replies.
What do you mean 'empty'?
By empty I was suggesting setting a string array element to = "" (vbNullstring/Nothing), like strArray(1, 3) = "Mary,had,a,little,lamb, whose,fleece,..." --> strArray(1, 3) = ""
So using 'Nothing" or "".
I am adding Erase(x, y) to all of the other procedures that use arrays, because at they are unused between inputs. I suppose the few I have that hold 1-2 digit bytes are not a worry, but I will still erase those.
LaVope,
So a string array like above, strArray(1, 3) would consume less memory if its contents was nothing ("") that if its contents were: "Mary,had,a,little,lamb,whose,fleece...", Yes?
There wouldn't be any memory earmarked for each element, correct?
With my 64 possible elements, this should help some.
This probably isn't much memory overall, but I'm running the app on an Acer netbook, Intel Atom, 1GB RAM, Win7 Starter.
I'll monitor memory usage next test.
-
Aug 28th, 2015, 12:00 PM
#5
Re: Best way to empty an element of a multidimensional array.
For variable length Strings specifically....
The array item (index) uses 4 bytes, regardless of the size of the string. But that index is just a pointer to the actual string data. That string data can contain 0 to n bytes worth of characters. Therefore, setting a string to "" uses 6 bytes for the string. Setting it to vbNullString uses zero bytes for the string. Setting strings to vbNullString is better than ""
Tags for this Thread
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
|