STL绳 - 何时何地使用 [英] STL Rope - when and where to use

查看:143
本文介绍了STL绳 - 何时何地使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在什么情况下,您会使用绳索在另一个STL容器上?

I was wondering under what circumstances you would use a rope over another STL container?

推荐答案


Ropes是一个可扩展字符串
实现:它们是为
高效操作设计的,涉及整个
字符串。诸如
赋值,连接和
子字符串等操作花费的时间接近
,与
字符串的长度无关。与C字符串不同,绳索是一个
代表非常
长字符串(如编辑缓冲区或
邮件)的合理表示。

Ropes are a scalable string implementation: they are designed for efficient operation that involve the string as a whole. Operations such as assignment, concatenation, and substring take time that is nearly independent of the length of the string. Unlike C strings, ropes are a reasonable representation for very long strings such as edit buffers or mail messages.

优点


  1. 包含long
    字符串的更快的连接和
    子字符串操作。在10兆字节绳索的
    中间插入一个字符应该是
    大约为
    微秒的数量级,即使保存了
    原始的副本。作为
    编辑历史的一部分。相比之下,这将
    花费一秒的时间用于
    常规的flat字符串
    表示。对于大多数应用程序,
    连接所需的时间可以视为
    常量。

  1. Much faster concatenation and substring operations involving long strings. Inserting a character in the middle of a 10 megabyte rope should take on the order of 10s of microseconds, even if a copy of the original is kept, e.g. as part of an edit history. In contrast, this would take on the order of a second for conventional "flat" string representation. The time required for concatenation can be viewed as constant for most applications. It is perfectly reasonable to use a rope as the representation of a file inside a text editor.

潜在的可能性是

完全合理的使用绳子作为
文件在
文本编辑器中的表示。更好的空间
性能。对
绳索的细微修改可以与
原件共享记忆。绳索分配在小的
块中,大大减少了内存

引入的碎片问题大块

Potentially much better space performance. Minor modifications of a rope can share memory with the original. Ropes are allocated in small chunks, significantly reducing memory fragmentation problems introduced by large blocks

(可能
引用计数)指针分配。
与引用计数的写时复制
实现不同,即使其中一个副本是
,稍后修改,这仍然主要是
。它是
非常便宜的检查点旧的
版本的字符串,例如。在编辑
历史记录中。

Assignment is simply a (possibly reference counted) pointer assignment. Unlike reference-counted copy-on-write implementations, this remains largely true even if one of the copies is subsequently slightly modified. It is very inexpensive to checkpoint old versions of a string, e.g. in an edit history.

可以查看函数
生成字符作为一个绳索。因此,
一条绳子可能是一个100MByte
文件,只有当字符串的
部分被检查时,才读取。
将字符串连接到
的末尾这样的文件不涉及读取
文件。 (目前此设施的
实施是
不完整。)

It is possible to view a function producing characters as a rope. Thus a piece of a rope may be a 100MByte file, which is read only when that section of the string is examined. Concatenating a string to the end of such a file does not involve reading the file. (Currently the implementation of this facility is incomplete.)



$ b b

http://www.sgi.com/tech/stl/Rope.html

这篇关于STL绳 - 何时何地使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆