为什么没有的boost

为什么没有的boost

本文介绍了为什么没有的boost :: copy_on_write_ptr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看到的不错的写入时复制指针的实施。它看起来pretty通用的和有用的,所以我的问题是:是否包含在任何的C ++工具包的这样一个类(升压,洛基等)?如果没有,我真的很想知道为什么,因为它是一个真正有用的成语,显然通用的实现看起来是可行的(像我联系)。

I just saw this nice copy-on-write pointer implementation. It looks pretty generic and useful, so my question is: Is such a class contained in any of the C++ toolkits (boost, loki, etc.)? If not, I'd really like to know why because it is a really useful idiom and apparently a generic implementation seems doable (like the one I linked to).

推荐答案

有很多在可能性的争论,以及至少一个提出的什么最终出来的版本的auto_ptr 是一个引用计数COW指针。

There was a lot of debate over the possibility, and at least one suggested version of what eventually came out as auto_ptr was for a reference counted COW pointer.

不幸的是,COW时间大多通过。制作COW指针(或牛什么)是线程安全的可以介绍严重的。

Unfortunately, the time for COW has mostly passed. Making a COW pointer (or COW-whatever) thread-safe can introduce serious performance problems.

编辑:重读,我觉得有必要指出的是,没有的所有的使用COW不一定过时。有很多次,它仍然是有意义的。一个线程安全增量的开销是pretty固定得多 - 所以这只是一个物体的大型必须是一个问题,或者多么昂贵的它是复制,奶牛是有道理的。还有一个(未修改)对象的拷贝次/地方,你拥有的地段的,并在内存中可以节省一个合理的权衡 - 在内存中的储蓄证明一些额外的处理器时间。如果你可以节省寻呼的的数据/从磁盘,你可以出人头地着急。

Rereading that, I feel obliged to point out that not all use of COW necessarily obsolete. There are times that it still makes sense. The overhead of a thread-safe increment is pretty much fixed -- so it's only a question of how large an object has to be, or how expensive it is to copy, for COW to make sense. There are also times/places that you have lots of copies of an (unmodified) object, and the savings in memory can be a reasonable tradeoff -- the savings in memory justify some extra processor time. If you can save paging a little data to/from disk, you can come out ahead in a hurry.

这篇关于为什么没有的boost :: copy_on_write_ptr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:32