>>Is there a nicer (or faster) way to cast a double[][] to a float[][]
>>than doing loops?
[quoted text clipped - 4 lines]
> any exist, but I could easily be wrong); but it'll just be doing loops inside,
> the same as if you did it yourself.
I was thinking of the likes as System.arraycopy() which is a native
method (as far as I can tell) so is maybe faster (?)...
But it needs to convert from double to float while copying...
Phil
Daniel Pitts - 29 Nov 2006 21:00 GMT
> >>Is there a nicer (or faster) way to cast a double[][] to a float[][]
> >>than doing loops?
[quoted text clipped - 11 lines]
>
> Phil
Try arraycopy out, I don't know if it'll work, but it might convert for
you.
Patricia Shanahan - 29 Nov 2006 21:08 GMT
>>>> Is there a nicer (or faster) way to cast a double[][] to a float[][]
>>>> than doing loops?
[quoted text clipped - 13 lines]
> Try arraycopy out, I don't know if it'll work, but it might convert for
> you.
One of its conditions for throwing an ArrayStoreException is "The src
argument and dest argument refer to arrays whose component types are
different primitive types."
Patricia
Chris Uppal - 30 Nov 2006 14:37 GMT
> I was thinking of the likes as System.arraycopy() which is a native
> method (as far as I can tell) so is maybe faster (?)...
<reminisce>I think it was when 1.3 came out, with the first release of the
Hotspot JIT, that the rumour went around that System.arraycopy() was now
implemented in Java, since that was as fast as a native version would have
been. I never did bother to check (I dunno why).</reminisce>
Whatever, I don't think that's true anymore. The 1.5 Sun JMV generates machine
code implementations for the various combinations of types and overlapping vs.
non-overlapping copies as part of its startup sequence, and (I presume) patches
them directly into the implementations of System.arraycopy(). Hard to imagine
Sun's engineers bothering with that unless they knew they could squeeze useful
extra speed that way (I must measure it someday...).
> But it needs to convert from double to float while copying...
Yeah. I suspect that's the problem. If there's no hyper-efficient, low-level,
bit-for-bit copy instruction(s) available, then there's not a lot to gain by
having a pre-packaged "wrapper" for low-level code.
-- chris