|
|
|
clone是不是比new对象要节省系统资源???
|
2003年05月25日 15:28
|
|
|
|
自己负责的一个功能模块完成了,目前在做重构,系统性能比优化前已经快了50%了, 前几天,一个同事提出一个疑问,我的商业逻辑部分有很多大对象(里面有很多属性,例如:名字,价格等). 我自己维护了一组对象缓冲,也就是把一组对象(每个对象都不同)放到了HashTable里,我在查询一行数据库数据的时候,不是去new,而是从这个HashTable里取. 同事说,这样和new是相同的,但是我有个疑问,既然说new浪费时间,clone我也看了相关的说明,好象比new是要省系统资源的? 对否???
|
|
|
|
|
|
Re: clone是不是比new对象要节省系统资源???
|
2003年05月27日 11:04
|
|
|
三个概念混乱在一起。 使用hashtable是cache,cache了那个对象的引用,保证那个对象不被垃圾回收。
new是重新生成一个对象,这当然很浪费,第一次生成后,将引用保存到cache中,就可以大幅度提高性能。
clone是对象的复制,是整个对象的复制,不是引用的复制。clone是类似new的.
|
|
|
|
|
|
Re: clone是不是比new对象要节省系统资源???
|
2003年05月27日 18:26
|
|
|
|
|
|
|
|
|
Re: clone是不是比new对象要节省系统资源???
|
2003年05月29日 06:14
|
|
|
|
Anybody know the difference between clone in java and copy constructor in C++?
|
|
|
|
|
|
Re: clone是不是比new对象要节省系统资源???
|
2003年06月03日 17:26
|
|
|
To Bruce: Clone and copy constructor are all used to create a new object according to a given prototype,except that the new object is exactly the same as prototype in clone, but may not in copy constructor( as you like )
|
|
|
|
|
|
Re: clone是不是比new对象要节省系统资源???
|
2003年06月04日 09:33
|
|
|
wwlhp@jdon.com Thank you very much. I got it. Java Clone and C++ copy constructor are all deep clone() if we don't take the object-in-object situation into consideration. Right?
|
|
|
|