SCJP, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
The clone method, creates new instances of the object/array to be cloned and sets the instance variables values/references for the new object the same as that of the original object. Whereas System.arraycopy does not create new objects but only copies the reference of the source array element by element and assigns them to the destination array.
"I'm not back." - Bill Harding, Twister
and decide if a shallow copy is really appropriate
BTW for this specific class it's not clear to me why you need to clone the FieldInfo[] at all
"I'm not back." - Bill Harding, Twister
I just don't think each separate record row needs its own copy of this metadata; in my design, a client calls getMetaData() to get a single DBMetaData object from the server.
...
I avoided set methods since I didn't see any reason anyone should change any metadata attributes after creation.
If you clone an array with a hundred elements or so, there's virtually no difference in performance
Regardless, I plan to continue to use clone() except in cases where I have established clone() is actually a performance bottleneck, as I still believe it's clearer in most cases.
"I'm not back." - Bill Harding, Twister
Some consider System.arraycopy to have the best performance, but an example run shows that this conclusion may not always be correct :
>java -cp . ArrayCopier performance 250000
Using clone: 360 ms
Using System.arraycopy: 181 ms
Using for loop: 150 ms
I just don't think each separate record row needs its own copy of this metadata; in my design, a client calls getMetaData() to get a single DBMetaData object from the server. This object is saved in an instance field on the client, and anytime it needs to access metadata, it just accesses that same instance.
"I'm not back." - Bill Harding, Twister
I disagree. Both clone() and System.arraycopy create new array and BOTH copy just references to another array. So in both cases only array is new created, but not its elements!!!
SCJP, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
we need to find new people to argue with
SCJP 6.0 | Free Java Beginner Video Course | Twitter: @MarcusBiel
I knew that guy would be trouble! Thanks tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
|