小编Quo*_*inh的帖子

为什么 pmr::string 在这些基准测试中如此缓慢?

尝试Pablo Halpern 撰写的以下关于多态内存资源的文章的第 5.9.2 节类 monotonic_buffer_resource中的示例:

文档编号:N3816
日期:2013-10-13
作者:Pablo Halpern
phalpern@halpernwightsoftware.com
多态内存资源 - r1
(原为 N3525 - 多态分配器)

文章声称:

monotonic_buffer_resource 类设计用于在内存用于构建一些对象然后在这些对象超出范围时立即释放的情况下非常快速的内存分配。

然后 :

monotonic_buffer_resource 的一个特别好的用途是为容器或字符串类型的局部变量提供内存。例如,以下代码将两个字符串连接起来,在连接后的字符串中查找单词“hello”,然后在找到或未找到该单词后丢弃连接后的字符串。连接的字符串预计不超过 80 字节长,因此使用小的 monotonic_buffer_resource [...] 为这些短字符串优化了代码。

我已经使用谷歌基准库boost.container 1.69 的多态资源对示例进行了基准测试,编译并链接到在 Ubuntu 18.04 LTS hyper-v 虚拟机上使用 g++-8 发布的二进制文件,代码如下:

// overload using pmr::string
static bool find_hello(const boost::container::pmr::string& s1, const boost::container::pmr::string& s2)
{
    using namespace boost::container;

    char buffer[80];
    pmr::monotonic_buffer_resource m(buffer, 80);
    pmr::string s(&m);
    s.reserve(s1.length() + s2.length());
    s += s1;
    s += s2; …
Run Code Online (Sandbox Code Playgroud)

c++ memory boost c++17

3
推荐指数
1
解决办法
2012
查看次数

标签 统计

boost ×1

c++ ×1

c++17 ×1

memory ×1