How to divide a huge array into small ones

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a huge sting array, there are about 1000 element in it.
How can I divide the huge array into small ones, and there are one 10
elements in a small one array?
 
ad said:
I have a huge sting array, there are about 1000 element in it.
How can I divide the huge array into small ones, and there are one 10
elements in a small one array?

1000 elements is small enough. Each element will be a pointer to a string
object so it won't be one huge chunk of memory. If you want to break it up
for other reasons create a new array and use the CopyTo function.

Michael
 
1000 isn't huge. When someone says "huge," I think on the order of
100,000 or 1,000,000.

You can use CopyTo to copy sections of the array into other arrays. Or
you can just loop through all 1000 elements one by one in a for loop,
which is slower but may be easier to understand and maintain.

Either way it will happen in the blink of an eye.
 
How to use CopyTo?
It have just a parameter, can I copy a range (like for index 5 to 15)
of a array to another array?
 
How to use CopyTo?
It have just a parameter, can I copy a range (like for index 5 to 15)
of a array to another array?

Use Array.Copy - the overload which takes two arrays and three ints.

Jon
 
I have a similar problem but with a huge array of double. Is there a way to
create an array that is a subset of a larger array without copying the
elements?
 
apm said:
I have a similar problem but with a huge array of double. Is there a way to create an array that is
a subset of a larger array without copying the elements?

Sort of.

Once again the question is ...WHY?
Memory considerations?
Duplication of data?

You can COPY a segment of your Array to a new Array, but you specified no copying.
You could create a class that ACTS like an Array and only looks at a subset of the data in the
master Array.
You would implement the IEnumerable and IEnumerator interfaces and set up an indexer on your class.
You pass in the Array and bounds to the constructor and it looks and feels like a SUB-Array.

All access to the underlying data would be through access methods, so this could cause performance
issues if the array is accessed frequently and if the JITer can't speed things up. (You would need
to test it out)

If you don't use 'foreach' of the SUB-Array you can even lose the IEnumerable and IEnumerator
interfaces and just do the indexer.

Hope this helps
Bill
 
Back
Top