Solved

redim vs. erase what is the difference

Posted on 2004-04-26
6
1,042 Views
Last Modified: 2006-11-17
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
Comment
Question by:cdb424ttm
  • 3
  • 2
6 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
redim can't be used with static arrays.

erase will completely delete a variable arrays and will only reset values of static arrays.
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
ya redim will remove memory (without the preserve)
erase will also do
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 33

Expert Comment

by:hongjun
Comment Utility
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
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
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
>>if i am not wrong, i guess redim is faster.
>>perhaps emoreau can comment on this.

I have no idea on this.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now