Best way to empty an element of a multidimensional array.-VBForums
Results 1 to 5 of 5

Thread: Best way to empty an element of a multidimensional array.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2009
    Posts
    64

    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.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,268

    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).

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,504

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VB and DPI Tutorial} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2009
    Posts
    64

    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.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,504

    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 ""
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VB and DPI Tutorial} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.