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++ 字符串(实习、绳索、写时复制等)
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01