R
rayreeves
How do I declare an array of references to the elements of an array of
values?
Ray
values?
Ray
rayreeves said:How do I declare an array of references to the elements of an array of
values?
rayreeves said:I don't want an array of arrays, I think "igd" has given me what I want.
I have the old problem of sorting efficiently. My values are structures,
and instead of shunting them about I want to shunt the references.
Thanks for all your help.
rayreeves said:This self-appointed project is to produce the world's fastest prime number
generator, where speed is the only criterion.
For example, on my 1300M processor my C++ code found the 5 000 000 primes
less than 100 000 000 in 14 secs. Unfortunately, I lost my hard drive and
all my source so I have to rewrite it, and it seems like a good time to try
in C#.
I can see that I have been under some misapprehensions about arrays and
references but I now understand that if I declare a class PRIMEVALUE with
two int fields p2 and pn and then declare an array pq = new PRIMEVALUE[some
size] it will take a suitable space on the heap and I can then populate the
elements with pq = new PRIMEVALUE(p2Value, pnValue) and those element
values will also be on the heap. Now I assume that when I interchange
elements of pq
with swap(pq, pq[j]) the references will be exchanged but the values
remain where they are.
I also assume that references are the size of one int, so moving them should
be faster than moving two ints.
Every msec counts! Garbage collection, I think, is irrelevant.
In C++ I understood perfectly well what was going on, but C# conceals so
much that I have some doubts that it is suitable for this purpose.