Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1210
  • Last Modified:

redim vs. erase what is the difference

redim vs. erase what is the difference?
I’m having a hard time understanding what the difference between using erase or redim to clear out an array. Can some one fill me in on the pros and Con’s of it?

Thanks
0
cdb424ttm
Asked:
cdb424ttm
  • 3
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
redim can't be used with static arrays.

erase will completely delete a variable arrays and will only reset values of static arrays.
0
 
hongjunCommented:
ya redim will remove memory (without the preserve)
erase will also do
0
 
hongjunCommented:
i am not sure what will be the difference in terms of "freeing memory" speed for hugh arrays.
if i am not wrong, i guess redim is faster.
perhaps emoreau can comment on this.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
David LeeCommented:
Redim changes the size of an array.  So, for example, I can redim an array and change the size while simultaneously disposing of its contents (if I don't use Redim Preserve).  Erase simply disposes of the contents of the array.  If the array happens to be dynamic, then it also disposes of the array elements themselves, not just their contents.  In contrast, if I use Redim I cannot reduce the array to fewer than one element.  Erase also releases the memory associated with a dynamic array.

dim myArray()          'Create a dynamic array
redim myArray(9)     'Resize the array to 10 elements with the lowest being element 0
redim myArray(0)     'Knocks the array down to one element
redim myArray(9)     'Back to 10 elements
erase myArray          'Array now has no elements

0
 
Éric MoreauSenior .Net ConsultantCommented:
>>if i am not wrong, i guess redim is faster.
>>perhaps emoreau can comment on this.

I have no idea on this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now