Best way to reset a array

C

Crirus

I have a big array 512*512 elements
Wich is the best way to reset the array to 0 on each element?

Redim without preserve, I have for loop and clear shared function
Wich one is best optimised for speed?
 
M

Mattias Sjögren

Redim without preserve, I have for loop and clear shared function
Wich one is best optimised for speed?

Why don't you try both ways, time it and let us know? I'm guessing
ReDim is faster (assuming there's enough memory available). But ReDim
just creates a new array, it doesn't affect the old one. So if memory
consumption is a concern you may want to use Array.Clear.



Mattias
 
A

aiax

ReDim arrMyArray(512,512) if want to clean out the array. Depending on the
datatype of the array, i.e. String, you would have to go through a loop and
set the value of each element to "0". If Int16, 32, 64 etc then ReDim will
reset all elements to 0.

Aiax
 
J

Jeremy Cowles

Redim without preserve, I have for loop and clear shared function
Wich one is best optimised for speed?

I am not 100% sure. You can always run a test and record your results, then
just choose the way that executes fastest.

You may want to ask the pro's about this, in the Performance ng
(microsoft.public.dotnet.framework.performance). One of the MS developers of
the JIT compiler resides there; he's usually very insightful.

HTH,
Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top