3
我想問一些關於我的算法的一部分的意見/建議。投射原始字體與修剪字節的方式
ByteBuffer bb = ByteBuffer.allocate(8);
bb.putLong(rs.getLong(index));//retrieve long from db (unsigned INT)
byte[] tmp = new byte[4];
bb.position(4);
bb.get(tmp);
(Inet4Address) InetAddress.getByAddress(tmp);
與
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt((int) rs.getLong(index));//retrieve long from db (unsigned INT)
bb.flip();
byte[] tmp = new byte[4];
bb.get(tmp);
(Inet4Address) InetAddress.getByAddress(tmp);
基本上,我想知道是否有鑄造性能差或者是它更好地使用更大的ByteBuffer。
感謝,問候,
馬立克
將這兩個塊封裝在方法中,編寫幾個測試並比較性能。爲什麼依靠其他人的意見,當你可以有確切的結果? – 2011-02-10 14:07:41