本文介绍了在现有代码中替换新的内存分配器的最佳解决方案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近几天,我获得了一些关于内存分配器的信息,而不是标准的 malloc()。对于具有多个线程的应用程序,有一些实现似乎比 malloc()好得多。例如, tcmalloc ptmalloc 似乎有更好的性能。



我有一个C ++应用程序在许多地方使用 malloc new 运算符。我认为用 ptmalloc 替换它们可以提高它的性能。但我不知道如何在运行在Linux上的C ++应用程序中使用 new 操作符?是否使用 malloc 或其他标准行为?



c $ c> new 内存分配器与旧的在代码中?是否有任何方式重写行为或 new malloc 或者我需要替换它们的所有调用由:

ptmalloc似乎是类似的(但如果你在Linux上,你可能已经在使用它了)。



我期望 $ new $ 调用 malloc ,但您可以通过在 malloc ,然后调用 new 。如果你的 new 没有调用 malloc ,。


During the last few days I've gained some information about memory allocators other than the standard malloc(). There are some implementations that seem to be much better than malloc() for applications with many threads. For example it seems that tcmalloc and ptmalloc have better performance.

I have a C++ application that uses both malloc and new operators in many places. I thought replacing them with something like ptmalloc may improve its performance. But I wonder how does the new operator act when used in C++ application that runs on Linux? Does it use the standard behavior of malloc or something else?

What is the best way to replace the new memory allocator with the old one in the code? Is there any way to override the behavior or new and malloc or do I need to replace all the calls to them one by one?

解决方案

From the TCMalloc documentation:

ptmalloc seems to be similar (but if you're on Linux, you're likely already using it because it's part of the GNU C library).

I would expect operator new to call malloc, but you can easily check for yourself by setting a breakpoint on malloc, then calling new. If your new doesn't call malloc, you can redefine it so that it does.

这篇关于在现有代码中替换新的内存分配器的最佳解决方案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:27