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++ 字符串(实习、绳索、写时复制等)


基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01