内存高效的 C++ 字符串(实习、绳索、写时复制等) [英] Memory-efficient C++ strings (interning, ropes, copy-on-write, etc)

查看:12
本文介绍了内存高效的 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++ 字符串(实习、绳索、写时复制等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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