473,383 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Best way to reset a array

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?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
3 6228
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
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

"Crirus" <Cr****@datagroup.ro> wrote in message
news:eb**************@TK2MSFTNGP11.phx.gbl...
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?

--
Cheers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #3
> 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

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ken | last post by:
How can I reset the initial form variables that are set with session statements when clicking on a button? I tried this but the function was not called: <?PHP function reset_form($none) {...
6
by: Shabam | last post by:
I have a text field that's pre-filled with data. Suppose the user edits it, but decides he wants to reset the data back to the original pre-filled data, how can I do that?
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
8
by: J. B. Moreno | last post by:
What's the best (i.e. fastest) way to find out if an array contains a given value? Other than looping, the only way I know to do it is to use an associative array/hash instead.... Is there a...
3
by: 0to60 | last post by:
I can declare and initialize a managed array of managed types like this: System::Object* array __gc = {...} Now, what do I do if I wanna reset that array to something else without...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
53
by: Sanders Kaufman | last post by:
I'm having a BLAST writing this app as OOP as PHP allows. It's one thing to discuss the dance, but it's a thing of beauty to see the performance. I'm noticing that the constructor is a "reset"...
5
by: bdbeames | last post by:
I have and array that I fill with elements in a function. I call it later and want to reset it so that it is empty so I can fill it with different elements and a different number of elements. How...
4
by: JuAn2226 | last post by:
can anyone help me to to do coding for reset and start again. i got 10 array of random number, 10 array for start time how do i reset the both array after the 10 array is filled and start filling up...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.