内存高效的 C++ 字符串(实习、绳索、写时复制等)
我的应用程序存在内存问题,包括复制大量字符串、使用与大量哈希表中的键相同的字符串等.我正在为我的字符串寻找一个基类,以使其非常高效.
My application is having memory problems, including copying lots of strings about, using the same strings as keys in lots of hashtables, etc. I'm looking for a base class for my strings that makes this very efficient.
我希望:
- 字符串实习(多个相同值的字符串使用相同的内存),
- 写时复制(我认为这在几乎所有 std::string 实现中都是免费的),
- 带绳子的东西会是一个奖励(对于 O(1)-ish 连接).
我的平台是 Linux 上的 g++(但这不太重要).
My platform is g++ on Linux (but that is unlikely to matter).
你知道这样的图书馆吗?
Do you know of such a library?
推荐答案
如果你的大部分字符串都是不可变的,Boost Flyweight 库可能适合您的需求.
If most of your strings are immutable, the Boost Flyweight library might suit your needs.
它会执行字符串实习,但我不相信它会进行写时复制.
It will do the string interning, but I don't believe it does copy-on-write.
相关文章