Memory-efficient C++ strings (interning, ropes, copy-on-write, etc)(内存高效的 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.
这篇关于内存高效的 C++ 字符串(实习、绳索、写时复制等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:内存高效的 C++ 字符串(实习、绳索、写时复制等)
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
